Computer Science Homework Solutions
Problem
#110528

Currency Conversion

I have problems with my switch menu performing the desired calculations. Also, the while statement is off.

The product converts amounts of money from one currency to another currency.  Five currencies are to be used.  The currencies are:

U.S. Dollars
Canadian Dollars
Japanese Yen
Indian Rupees
British Pounds


A user enters an amount of money in one of the five currencies and requests to convert that money into another currency.  The equivalent amount of money in the requested currency is displayed to the user.

Attached file(s):
Attachments
CurrencyConverter.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

CurrencyConverter.doc
#include

#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;}



}

}

}
Solution
What is this?
By OTA - Overall OTA Rating
Marcia Wert, MS - 4.1/5
Purchase Cost Now
$2.19 CAD (was ~$3.99)
Included in Download
  • Plain text response
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
Browse