Code:
/*Currency Conv Control Module*/
#include <stdio.h>
#include "currencyconv.h" /* defines constants, declares functions */
int main(void)
{
float us_dollars;
float currency;
int user_input;
while ((user_input = menu()) != QUIT)
{
switch(user_input)
{
case 1 : currency = EUR;
break;
case 2 : currency = GBP;
break;
case 3 : currency = INR;
break;
case 4 : currency = CAD;
break;
case 5 : currency = AUD;
break;
}
us_dollars = getus_dollars();
convert_rate(currency, us_dollars);
}
printf("Goodbye!");
getch();
return 0;
}
/* currencyconv.c -- function support module */
#include <stdio.h>
#include "currencyconv.h"
int menu(void)
{
int user_input;
int selection;
printf("\n%s%s\n", DECO, DECO);
printf(" CURRENCY CONVERTER\n\n\n");
printf(" You've just entered the Currency Conversion Program\n\n\n");
printf(" Select a number between 1 and 5 to pick the currency you\n");
printf(" would like to convert to from US Dollars\n\n");
printf(" Select number 6 to exit the program\n\n\n");
printf(" Enter Number (1) Key to Select EUR or Euro\n\n");
printf(" Enter Number (2) Key to Select GBP or British Pounds\n\n");
printf(" Enter Number (3) Key to Select INR or Indian Rupee\n\n");
printf(" Enter Number (4) Key to Select CAD or Canadian Dollars\n\n");
printf(" Enter Number (5) Key to Select AUD or Australian Dollars\n\n");
printf(" Enter Number (6) Key to Quit\n\n");
printf("%s%s\n", DECO, DECO);
while ((selection = scanf("%d", &user_input)) != 1 || (user_input < 1 || user_input > 6))
{
if (selection != 1)
scanf("%*s");
printf("Your number is not a selection. Please enter a number between 1 and 6.\n");
}
return user_input;
getch();
}
int getus_dollars(void)
{
int us_dollars;
printf("Please enter the amount in US Dollars you would like to convert: ");
while (scanf("%f", &us_dollars) != 1)
{
scanf("%*s");
printf("Error!!! Please enter that amount again in US Dollars, such as 8.00\n");
}
return us_dollars;
getch();
}
float convert_rate(float currency, float us_dollars)
{
float total = 0.00;
total = us_dollars * currency;
printf("Your US Dollars in XXX is $%0.2f.\n", total);
//return total;
//getch();
}
/* currencyconv.h -- constants and declarations for currencyconv.c */
/*All constants/rates obtained on 11/3/13 from XE.com*/
#define EUR 0.741
#define GBP 0.628
#define INR 61.75
#define CAD 1.04
#define AUD 1.06
#define QUIT 6
#define DECO "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
int menu(void); // shows list of choices
Hello All -
This is $$ converter program I created that is split up over 3 files. It takes the users input in US Dollars and converts it to the currency selected. When executing the program I am encountering a small problem. It actually isn't converting anything and returns 0.00 dollars. Could someone please look at this and tell me where the problem lies and how I can fix it.
I would like for it to convert the amount entered into the currency selected. I would also like to add in the print statement the type of currency the user has selected.
Any help would be greatly appreciated.