Foriegn currency to another foriegn currency exchange calculation issue

Posted on 2006-06-20
Last Modified: 2011-09-20
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;
                     case 2:
                              usd = yen*amt;
                     case 3:
                              usd = pound*amt;
                     case 4:
                              usd = can*amt;
                     case 5:
                              usd = ruble*amt;
                        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:
                             printf("\n\nYou entered $%.2f which equals $%.2f pesos\n",amt,usd);
                     case 2:
                              usd = amt/yen;
                              printf("\n\nYou entered $%.2f which equals $%.2f Yen\n", amt,usd);
                     case 3:
                              total = pound*amt;
                              printf("\n\nYou entered $%.2f which equals $%.2f Pounds\n", amt,usd);
                     case 4:
                              total = can*amt;
                              printf("\n\nYou entered $%.2f which equals $%.2f CAD\n", amt,usd);
                     case 5:
                              total = ruble*amt;
                              printf("\n\nYou entered $%.2f which equals $%.2f rubles\n", amt,usd);
                              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*/
                    }/*end if statement*/      
 }/*end while loop*/      
                   printf("\n\nHave a nice day!");

   //else }
   //       printf("you entered and incorrect number, please choose from 1-5");


}/*end main program*/
Question by:Cabochick05
LVL 24

Assisted Solution

fridom earned 50 total points
ID: 16940345
I think you would yourself a favour while splitting the problem into smaller pieces.
So are you getting the proper result for the first round (amount of the other currencies in Dollar?

It seems to me that the first switch does that.

But the second switch does not what you want it to do. I'd argue.

So let's see the problem

foreign currency -> US-$.
So let us take a simple exchange rate like 2 foo/US-$
and 3 bars / US-$

first round
foreign currency foo into US-$
amount = 100 foos

US$ = foos /exchange_rate

            100 / 2 = 50
So we now know that 100 foos are 50 US-$

Now getting into the next currency

50 US-$ = x bars / 3

We solve that this way
50 US $ * 3 bars/US-$ = 150 bars

So this is the way you have to calculate.

Check your calculation against it and get it into sync.

I suggest first gettign it work for one currency (yes write  program that only does that)

And then look for generalice it later. Your problem is that you do not have the calculation right, then it should be clear that you can not write  a program doing the "right" calculation also.

Keep calm and solve you problem one step by the other. Many small steps will get you anywhere someday.


Accepted Solution

Dimkov earned 450 total points
ID: 16940619
the second switch  should be

            switch (choice2)
            {/*begin switch/case*/    

            case 1:
                  printf("\n\nYou entered $%.2f which equals %.2f pesos\n",usd,usd/peso);
            case 2:                   
                  printf("\n\nYou entered $%.2f which equals %.2f Yen\n", usd,usd/yen);
            case 3:                   
                  printf("\n\nYou entered $%.2f which equals %.2f Pounds\n",usd,usd/pound);
            case 4:                   
                  printf("\n\nYou entered $%.2f which equals %.2f CAD\n",usd,usd/can);
            case 5:                   
                  printf("\n\nYou entered $%.2f which equals %.2f rubles\n",usd, usd/ruble);
                  printf("\nYou did not choose a valid currency 1 - 5:\n");

            }/*end switch/case*/

Tell me if it helps,

Regards, Dimkov

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question