#include
int main()
{
/* Setting up variables for conversion ,each rate is equal to one US
Dollar. */
/* Generic variables */
int input; /* This is selection of first currency. */
int input2; /* This is selection of second currency. */
int exit_flag = 0, valid_choice;
float US_amount; /* This is the amount of one dollar. */
float result; /* Displays conversions. */
char tryagain; /* Stores the denominations label. */
char user_input;
float amount;
/* Variables and rates for US currency.Update once a week. */
float US_US = 1.00;
float US_BRIT = .513031;
float US_CAN = 1.1356;
float US_JAP = 116.29;
float US_IND = 44.54;
while( exit_flag == 0 ) {
valid_choice = 0;
while( valid_choice == 0)
{
/* Pick a start currency, if not US then convert yo US, then
multiply by constant of desired currency to get desired currency. */
/* Begin Application */
/* Printing Title Bar */
printf("Currency Conversion Application\n\n");
retry: /*Retry at this point if 1 st validation fails. */
/* Menu that prints currency options. */
printf("Please Select Your Currency\n"); /* This prompt tells
the user to select the currency to select from */
printf("\n");
printf("1. US Dollar\n");
printf("2. Canadian Dollar\n");
printf("3. British Pound\n");
printf("4. Japaneese Yen\n");
printf("5. Indian Rupee\n");
printf("6. Exit\n");
printf("Selection:");
scanf("%d", &input);
printf("\n\n");
/* Validate Section */
{
if(input<1)
goto retry ;
if(input>5)
goto retry ;
}
retry1: /* Retry at this point if 2nd validation fails. */
/*printf("Your selection was: %d\n\n", input) */
printf("Convert to the following currency.\n"); /* This prompts
the user to select the currency to convert to */
printf("Selection:");
scanf("%d", &input2);
printf("\n\n");
/* Validate Section */
{
if(input2<1)
goto retry1;
if(input2>5)
goto retry1;
}
printf("Please enter amount to convert:"); /* Prompt user to enter
amount to convert. */
scanf("%f", &amount); /* Store user entry into memory. */
printf("Your selections are: %d %d %3.2f \n", input, input2,
amount);
if ((input == 6) || (input2 == 6)), valid_choice = 1;
else printf("\007 Error. Invalid menu choice selected.\n");
exit(0);
return 0;
printf("Continue (Y/N)?\n");
scanf(" %c", &user_input );
user_input = toupper( user_input );
if((user_input == 'Y') || (user_input == 'N') ) valid_choice = 1;
else printf("\007Error: Invalid choice\n");
/* If not US currency, then convert to US by dividing the desired
currency's constant. */
switch(input)
{
case 1: /* US, do nothing */
US_amount=amount;
break;
case 2: /* Canadien */
US_amount=amount/US_CAN;
break;
case 3: /* British */
US_amount=amount/US_BRIT;
break;
case 4: /* Japaneese */
US_amount=amount/US_JAP;
break;
case 5: /* India */
US_amount=amount/US_IND;
break;
case 6: /* Giving the user the option to exit. */
exit_flag = 1;
break;
default :
printf("Invalid Option Selected. Please select an option from
the menu!\n");
break;
}
/* Now to do another one of these to convert to. */
switch(input2)
{
case 1 : /* US, do nothing. */
US_amount=amount;
break;
case 2: /* Canadien */
US_amount=amount/US_CAN;
break;
case 3: /* British */
US_amount=amount/US_BRIT;
break;
case 4: /* Japaneese */
US_amount=amount/US_JAP;
break;
case 5: /* India */
US_amount=amount/US_IND;
break;
case 6: /* Give user the opportunity to exit program. */
printf("Exiting Program Now......Bye!!!\n\n");
break;
default:
printf("Invalid Option Selected. Please select an option from
the menu!\n");
}
/* Loop to repeat application*/
printf("\n\nWould you like to Run again?\n\n (Y/N)");
scanf("%c", &tryagain);
{if (tryagain == 'Y');
goto retry;}
}
}
}
