|
program we did:
//This program converts the U.S. Dollar into Swiss Francs, Mexican Pesos, Canadian Dollars, Japanese Yen, //and Euro Dollars, as well as calculating the user's input //Last updated on 2-28-05 #include <stdio.h>//including the standard input output library int main(void) #define Franc 1.1863//Hardcoding the value of the Franc conversion #define Peso 11.1625//Hardcoding the value of the Peso conversion #define Canadian 1.2363//Hardcoding the value of the Canadian dollar conversion #define Yen 105.2166//Hardcoding the value of the Yen conversion #define Euro .7669//Hardcoding the value of the Euro conversion { //Next, I am initializing a group of variables that will represent the conversion of the user's input float famount=0.0; float pamount=0.0; float camount=0.0; float yamount=0.0; float euamount=0.0; int status=0; //The following variables will be the input from the user float fnum=0.0; float pnum=0.0; float cnum=0.0; float ynum=0.0; float eunum=0.0; int selection=0;//Initializing an integer for the user's selection choices printf("Carl's Currency Conversion\n\n"); printf("Welcome to Carl's Currency Conversion!\n"); printf("Are you planning on doing some travelling?\n"); printf("Do you want to know what the U.S. Dollar will convert to in other countries?\n"); printf("This program will give you an idea!\n\n"); //Two new lines for better readability printf("Let's take a look at what 1 U.S. Dollar converts to....\n\n"); printf("1 U.S. Dollar is equal to %.4f Swiss Francs.\n\n", Franc);//Generating output that shows the conversion printf("1 U.S. Dollar is equal to %.4f Mexican Pesos.\n\n", Peso);//Generating output that shows the conversion printf("1 U.S. Dollar is equal to %.4f Canadian Dollars.\n\n",Canadian);//Generating output that shows the conversion printf("1 U.S. Dollar is equal to %.4f Japanese Yen.\n\n", Yen);//Generating output that shows the conversion printf("1 U.S. Dollar is equal to %.4f Euro Dollars.\n\n", Euro);//Generating output that shows the conversion while (selection!=6)//This loop continues until the user selects "6" { printf("What currency do you want to convert?\n"); printf ("Enter 1 for Swiss Francs.\n"); printf ("Enter 2 for Mexican Pesos.\n"); printf ("Enter 3 for Canadian Dollars.\n"); printf ("Enter 4 for Japanese Yen.\n"); printf ("Enter 5 for Euro Dollars.\n"); printf ("Enter 6 to quit.\n"); status=scanf("%d", &selection);//Getting user input and value for "status" if(status==0)//Checking for user error { printf("Invalid entry!\n");//Error message getchar(); } else if (selection==1) { printf("You selected Swiss Francs.\n"); printf("Please enter the amount of US Dollars you would like to convert into Francs!\n");//Prompting user input status=scanf("%f", &fnum);//Getting user input and value for "status" if (status==0)//checking for user error { printf("Invalid entry!\n"); getchar(); } else if (status==1) { famount=fnum*Franc; //user input multiplied by hardcoded value printf("%.2f U.S. Dollars is equal to %.4f Swiss Francs.\n\n", fnum,famount); //outputting the result }} else if (selection==2) { printf("You have selected Mexican Pesos.\n"); printf("Please enter the amount of US Dollars to convert into Mexican Pesos!\n");//Prompting user input status=scanf("%f", &pnum);//Getting user input and value for "status" if(status==0)//checking for user error { printf("Invalid entry!\n");//error message getchar(); } else if (status==1) { pamount=pnum*Peso;//user input multiplied by hardcoded value printf("%.2f U.S. Dollars is equal to %.4f Mexican Pesos.\n\n", pnum, pamount);//outputting the result }} else if (selection==3) { printf("You have selected Canadian Dollars.\n"); printf("Please enter the amount of US Dollars to convert into Canadian Dollars.\n");//Prompting user input*/ status=scanf("%f", &cnum);//Getting user input and value for "status" if(status==0)//checking for user error { printf("Invalid entry!\n");//error message getchar(); } else if (status==1) { camount=cnum*Canadian;//user input multiplied by hardcoded value printf("%.2f U.S. Dollars is equal to %.4f Canadian Dollars.\n\n",cnum, camount);//outputting the result }} else if (selection==4) { printf("You selected Japanese Yen.\n"); printf("Please enter the amount of US Dollars to convert into Japanese Yen.\n");//Prompting user input status=scanf("%f", &ynum);//Getting user input and value for "status" if(status==0)//checking for user error { printf("Invalid entry!\n");//error message getchar(); } else if (status==1) { yamount=ynum*Yen;//user input multiplied by hardcoded value printf("%.2f U.S. Dollars is equal to %.4f Japanese Yen.\n\n", ynum, yamount);//outputting the result }} else if (selection==5) { printf("You have selected Euro Dollars.\n"); printf("Please enter the amount of US Dollars to convert into Euro Dollars.\n");//Prompting user input status=scanf("%f", &eunum);//Getting user input and value for "status" if(status==0)//Checking for user error { printf("Invalid entry!\n");//error message getchar(); } else if (status==1) { euamount=eunum*Euro;//user input multiplied by hardcoded value printf("%.2f U.S. Dollars is equal to %.4f Euro Dollars.\n\n", eunum, euamount);//outputting the result }} else if (selection==6) printf("Thank you for using Carl's Currency Conversion! Have a safe trip!\n"); else printf("Invalid entry!\n");//error message for entering a number not mentioned as a choice continue;//continuing the loop } return 0;//returning a value of 0 }
|