Solved

Foriegn currency to another foriegn currency exchange calculation issue

Posted on 2006-06-20
2
362 Views
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;
                             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*/
0
Comment
Question by:Cabochick05
2 Comments
 
LVL 24

Assisted Solution

by:fridom
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.

Regards
Friedrich
0
 
LVL 3

Accepted Solution

by:
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);
                  break;
            case 2:                   
                  printf("\n\nYou entered $%.2f which equals %.2f Yen\n", usd,usd/yen);
                  break;
            case 3:                   
                  printf("\n\nYou entered $%.2f which equals %.2f Pounds\n",usd,usd/pound);
                  break;
            case 4:                   
                  printf("\n\nYou entered $%.2f which equals %.2f CAD\n",usd,usd/can);
                  break;
            case 5:                   
                  printf("\n\nYou entered $%.2f which equals %.2f rubles\n",usd, usd/ruble);
                  break;  
            default:
                  printf("\nYou did not choose a valid currency 1 - 5:\n");


            }/*end switch/case*/

Tell me if it helps,

Regards, Dimkov
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

820 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