/* * modswitch3.c * Project 1 * Chapter 7 * By John Stile * Modify modswitch3a.c form chapter 6 * Put the program in a while loop until the user chooses * a new menu option to quit the program */ #include /* User-defined functions */ char ChooseMenu(void) // header for menu generator: returns char, takes nothing { //system("clear"); system("date"); printf("************************************\n"); printf("***Welcome to conversion world!***\n"); printf("1) Converts Miles to Kilometers.\n"); printf("2) Converts Kilometers to Miles.\n"); printf("3) Convets Pounds to Kilograms.\n"); printf("4) Converts Kilograms. to Pounds\n"); printf("q) Quti the program\n"); printf("\n\n"); printf("Enter your menu choice: "); return getchar(); } void mi2km(void) // header for miles to kilometers: returns nothin, takes nothing { float mile; getchar(); // clean imput buffer printf("Enter a distance in Miles:"); scanf("%f", &mile); printf("%.1f(Mi) is %.1f(Km)\n", mile, (mile*1.6) ); } void km2mi(void) { float kilo; getchar(); printf("Enter a distance in Kilometers:"); scanf("%f", &kilo); printf("%.1f(Km) is %.1f(Mi)\n", kilo, (kilo/1.6) ); } void lb2kg(void) { float pound; getchar(); printf("Enter a weight in Pounds:"); scanf("%f", £); printf("%.1f(lb) is %.1f(kg)\n", pound, (pound*0.45) ); } void kg2lb(void) { float kilogram; getchar(); printf("Enter a mass in Kilograms:"); scanf("%f", &kilogram); printf("%.1f(kg) is %.1f(lb)\n", kilogram, (kilogram/0.45) ); } /* *** main function *** */ int main(void) { char choice; while( choice=ChooseMenu() ) { switch (choice) { case '1': mi2km(); break; case '2': km2mi(); break; case '3': lb2kg(); break; case '4': kg2lb(); break; case 'q': printf("Qutting program\n"); return 0; default: printf("You entered an invalud choice.\n"); } getchar(); // clear input buffer printf("\n\n"); } return 0; }