Cabochick05
asked on
Foriegn currency to another foriegn currency exchange calculation issue
Hi all,
I cannot get my foreign currency to exhange to another foreign currency. We are supposed to use two switch cases statements. We were advised to use a formula that takes the 1st foreign currency to USD and then to another foriegn currency which will allow the exchange from one FC to FC. Here is what I have so far. I've racked my brain on this all week and it's due tomorrow at 6p mst. Nothing like waiting until the last minute! Any help would be appreciated! I just need to keep it simple! Thanks so much!
Susan =)
/*6/19/06 POS370 Susan Johnson Individual Assignment 3 of 3:
* Week 1 - Find 5 foreign currencies and display conversion in us dollars
* Week 2 - Offer the user a choice of which foreign currency and how much to exchange into USD
* Week 3 - Change any currency to any currency. Use two case statements one is from foriegn currency to USD.*/
#include <stdio.h>
main ()
{
float peso = 0.0885426;
float yen = 0.00895015;
float pound = 1.8775;
float can = 0.910415;
float ruble = 0.0374186;
float amt = 0.0;
float usd = 0.0;
float total = 0.0;
int choice1;
int choice2;
int promptUSD;
int promptXFC;
int x = 0;
printf("\nForiegn Currency Conversion Table\n");
printf("\n\t1: Mexican peso");
printf("\n\t2: Japanese yen");
printf("\n\t3: British pound");
printf("\n\t4: Canadian dollar");
printf("\n\t5: Russian ruble");
while (x == 0)
{/*begin while loop*/
printf( "\n\nChoose a foreign currency using 1 - 5: ");
scanf ( "%d", &choice1);
if (choice1 >= 1 && choice1 <= 5)
{/*begin if statement*/
printf( "\n\nEnter the amount to be converted: ");
scanf( "%f", &amt);
switch (choice1)
{/*begin switch/case*/
case 1:
usd = peso*amt;
break;
case 2:
usd = yen*amt;
break;
case 3:
usd = pound*amt;
break;
case 4:
usd = can*amt;
break;
case 5:
usd = ruble*amt;
break;
default:
printf("\nYou did not choose a valid currency 1 -5:\n");
}/* end if*/
}/* end switch/case*/
printf( "\n\nUse 1 - 5 again to exchange your amount to another currency: ");
scanf ( "%d", &choice2);
switch (choice2)
{/*begin switch/case*/
case 1:
usd=amt/peso;
printf("\n\nYou entered $%.2f which equals $%.2f pesos\n",amt,usd);
break;
case 2:
usd = amt/yen;
printf("\n\nYou entered $%.2f which equals $%.2f Yen\n", amt,usd);
break;
case 3:
total = pound*amt;
printf("\n\nYou entered $%.2f which equals $%.2f Pounds\n", amt,usd);
break;
case 4:
total = can*amt;
printf("\n\nYou entered $%.2f which equals $%.2f CAD\n", amt,usd);
break;
case 5:
total = ruble*amt;
printf("\n\nYou entered $%.2f which equals $%.2f rubles\n", amt,usd);
break;
default:
printf("\nYou did not choose a valid currency 1 - 5:\n");
}/*end switch/case*/
printf("\n\nWould you like to exchange your amount to another currency? 1 for yes, 2 for no: ");
scanf("%d", &promptUSD);
if (promptUSD == 2)
{/*begin if statement*/
x=1;
}/*end if statement*/
}/*end while loop*/
printf("\n\nHave a nice day!");
//else }
// printf("you entered and incorrect number, please choose from 1-5");
getchar();
}/*end main program*/
I cannot get my foreign currency to exhange to another foreign currency. We are supposed to use two switch cases statements. We were advised to use a formula that takes the 1st foreign currency to USD and then to another foriegn currency which will allow the exchange from one FC to FC. Here is what I have so far. I've racked my brain on this all week and it's due tomorrow at 6p mst. Nothing like waiting until the last minute! Any help would be appreciated! I just need to keep it simple! Thanks so much!
Susan =)
/*6/19/06 POS370 Susan Johnson Individual Assignment 3 of 3:
* Week 1 - Find 5 foreign currencies and display conversion in us dollars
* Week 2 - Offer the user a choice of which foreign currency and how much to exchange into USD
* Week 3 - Change any currency to any currency. Use two case statements one is from foriegn currency to USD.*/
#include <stdio.h>
main ()
{
float peso = 0.0885426;
float yen = 0.00895015;
float pound = 1.8775;
float can = 0.910415;
float ruble = 0.0374186;
float amt = 0.0;
float usd = 0.0;
float total = 0.0;
int choice1;
int choice2;
int promptUSD;
int promptXFC;
int x = 0;
printf("\nForiegn Currency Conversion Table\n");
printf("\n\t1: Mexican peso");
printf("\n\t2: Japanese yen");
printf("\n\t3: British pound");
printf("\n\t4: Canadian dollar");
printf("\n\t5: Russian ruble");
while (x == 0)
{/*begin while loop*/
printf( "\n\nChoose a foreign currency using 1 - 5: ");
scanf ( "%d", &choice1);
if (choice1 >= 1 && choice1 <= 5)
{/*begin if statement*/
printf( "\n\nEnter the amount to be converted: ");
scanf( "%f", &amt);
switch (choice1)
{/*begin switch/case*/
case 1:
usd = peso*amt;
break;
case 2:
usd = yen*amt;
break;
case 3:
usd = pound*amt;
break;
case 4:
usd = can*amt;
break;
case 5:
usd = ruble*amt;
break;
default:
printf("\nYou did not choose a valid currency 1 -5:\n");
}/* end if*/
}/* end switch/case*/
printf( "\n\nUse 1 - 5 again to exchange your amount to another currency: ");
scanf ( "%d", &choice2);
switch (choice2)
{/*begin switch/case*/
case 1:
usd=amt/peso;
printf("\n\nYou entered $%.2f which equals $%.2f pesos\n",amt,usd);
break;
case 2:
usd = amt/yen;
printf("\n\nYou entered $%.2f which equals $%.2f Yen\n", amt,usd);
break;
case 3:
total = pound*amt;
printf("\n\nYou entered $%.2f which equals $%.2f Pounds\n", amt,usd);
break;
case 4:
total = can*amt;
printf("\n\nYou entered $%.2f which equals $%.2f CAD\n", amt,usd);
break;
case 5:
total = ruble*amt;
printf("\n\nYou entered $%.2f which equals $%.2f rubles\n", amt,usd);
break;
default:
printf("\nYou did not choose a valid currency 1 - 5:\n");
}/*end switch/case*/
printf("\n\nWould you like to exchange your amount to another currency? 1 for yes, 2 for no: ");
scanf("%d", &promptUSD);
if (promptUSD == 2)
{/*begin if statement*/
x=1;
}/*end if statement*/
}/*end while loop*/
printf("\n\nHave a nice day!");
//else }
// printf("you entered and incorrect number, please choose from 1-5");
getchar();
}/*end main program*/
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.