Advertisement

05.21.2008 at 02:42PM PDT, ID: 23422636
[x]
Attachment Details

Currency Conversion Program Error

Asked by lskair in C Programming Language, Miscellaneous Programming

Tags: C

I created a simple currency conversion program last week and would like to add to it to give the user a choice to convert either to or from USD.  So, I added selections, and set up the formulas for each scenario.  However, when I run it, I am having a slight problem when choosing Option 1 (convert from USD to foreign currency).  The problem is that it doesn't end the program correctly, and it tries to ask for another amount to be input.  I am not sure where the problem is, but as soon as I find it, I'd like to then give the user the option to start over, which I think can be done with a while loop.  Any suggestions of what might be causing the program to not exit after calculations are completed, in Selection 1, would be appreciated.

Thanks.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
//This program displays conversions of USD amounts to the selected country's currency 
//Countries available: Canada, India, Australia, Mexico, and Japan 
#include<stdio.h>
int main(void)
 
{
   /*Declare floaters*/
//The below foreign currencies are the floaters available for conversion
      float Canada_Dollars;
      float Indian_Rupees;
      float Australian_Dollars;
      float Mexican_Pesos;
      float Japanese_Yen;
      float US_Dollars;
      int choice;
      int iSelection = 0;	
	
//Currencies retrieved from http://www.xe.com/ucc/ 
      /*List of Currency Conversions to be converted to US dollar*/
      printf("Currency Conversion Program\n");
      printf("\n");
      printf("Foreign currency equivalent to $1 US Dollar (USD)\n");
 
      printf("$1.00 USD equals 0.999850 Canadian Dollars \n");
      printf("$1.00 USD equals 42.5900 Indian Rupees (INR)\n");
      printf("$1.00 USD equals 1.04750 Australian Dollars (AUS)\n");
      printf("$1.00 USD equals 10.4062 Mexican Pesos (MXN)\n");
      printf("$1.00 USD equals 104.080 Japanese Yen (JPY)\n");
      printf("\n");
     
      printf("Please select what you want to do\n");
      
      printf("Press [1] to convert USD to foreign currency\n");
      printf("Press [2] to convert foreign currency to USD\n");
      printf("\n");
      scanf("%d", &iSelection);
if (iSelection == 1){
      printf("Enter 1-5 for country to convert US dollars to\n");
      printf("\n");
      printf("Press [1] for Canada \n");
      printf("\n");
      printf("Press [2] for Indian Rupees  \n");
      printf("\n");
      printf("Press [3] for Australian Dollars\n");
      printf("\n");
      printf("Press [4] for Mexican Pesos \n");
      printf("\n");
      printf("Press [5] for Japanese Yen \n");
 
      printf("\n");
      printf("\n");
 
            printf("\nEnter choice 1 through 5 to find conversion of USD:");      
            scanf("%i",&choice);
}
//USD is entered to correspond with selected choice (1-5).  USD amount is then converted to selected country's currency
            switch(choice){
            
            case 1:
                  printf("Enter amount in US Dollars:");
                  scanf("%f",&US_Dollars);
                  
                  printf("\nCanada dollars equivalent is ");
                  printf("%f", US_Dollars*0.999850);
 
                  break;
            case 2:
                  printf("Enter amount in US Dollars: ");
                  scanf("%f",&US_Dollars);
 
                  printf("\nIndian Rupees equivalent is: ");
                  printf("%f", US_Dollars*42.5900);
                  break;
            case 3:
                  printf("Enter amount in US Dollars: ");
                  scanf("%f",&US_Dollars);
             
                  printf("\nAustralian Dollars equivalence is: ");
                  printf("%f", US_Dollars*1.04750);
                  break;
             
             case 4: 
                  printf("Enter amount in US Dollars: ");
                  scanf("%f",&US_Dollars);
             
                  printf("\nMexican Pesos equivalence is: ");
                  printf("%f", US_Dollars*10.4062);
                  break;
             
             case 5:
                  printf("\nEnter amount in US Dollars: ");
                  scanf("%f", &US_Dollars);
             
                  printf("\nJapanese Yen equivalence is: ");
                  printf("%f", US_Dollars*104.080);
                  break; 
                  
 
             default: 
                 printf("\nPlease choose valid selection 1 to 5");
                  break;
                  
                           
            }
     printf("\n"); 
      {
      printf("End of program");
      printf("\n");
      printf("Press Enter to close program.");
      }
  if (iSelection == 2){
      printf("Enter 1-5 for country you wish to convert to USD\n");
      printf("\n");
      printf("Press [1] for Canada \n");
      printf("\n");
      printf("Press [2] for Indian Rupees  \n");
      printf("\n");
      printf("Press [3] for Australian Dollars\n");
      printf("\n");
      printf("Press [4] for Mexican Pesos \n");
      printf("\n");
      printf("Press [5] for Japanese Yen \n");
 
      printf("\n");
      printf("\n");
 
            printf("\nEnter choice 1 through 5 to find conversion from foreign to USD:");      
            scanf("%i",&choice);
}
//Foreign dollar is entered to correspond with selected choice (1-5).  Foreign amount is then converted to US Dollars
            switch(choice){
            
            case 1:
                  printf("Enter amount in Canada Dollars:");
                  scanf("%f",&Canada_Dollars);
                  
                  printf("\nUSD equivalent is ");
                  printf("%f", Canada_Dollars*1.01701);
 
                  break;
            case 2:
                  printf("Enter amount in Indian Rupees: ");
                  scanf("%f",&Indian_Rupees);
 
                  printf("\nUSD equivalent is: ");
                  printf("%f", Indian_Rupees*0.0234028);
                  break;
            case 3:
                  printf("Enter amount in Australian Dollars: ");
                  scanf("%f",&Australian_Dollars);
             
                  printf("\nUSD equivalence is: ");
                  printf("%f", Australian_Dollars*0.962373);
                  break;
             
             case 4: 
                  printf("Enter amount in Mexican Pesos: ");
                  scanf("%f",&Mexican_Pesos);
             
                  printf("\nUSD equivalence is: ");
                  printf("%f", Mexican_Pesos*0.0964981);
                  break;
             
             case 5:
                  printf("\nEnter amount in Japanese Yen: ");
                  scanf("%f", &Japanese_Yen);
             
                  printf("\nUSD equivalence is: ");
                  printf("%f", Japanese_Yen*0.00971057);
                  break; 
                  
 
             default: 
                 printf("\nPlease choose valid selection 1 to 5");
                  break;
                  
                           
            }
     printf("\n"); 
 
 {
      printf("End of program");
      printf("\n");
      printf("Press Enter to close program.");
      }
      getchar ();
      return 0; 
 {
      printf("End of program");
      printf("\n");
      printf("Press Enter to close program.");
      }
      getchar ();
      return 0; 
       
 
 }
//1.1 conversions not calculating correctly. Converting to 0.00000 
//1.2 fixed conversions, had entered country instead of US_dollars 
/*1.3 compiled correctly, wouldn't link -- error Linker Error (Severity 4)
	Module "a" in file "c:\program files\miracle c\currency_css561.obj"
	references unresolved external "_prinf"
	at offset 02B1H in segment "_text". --found error "prinf" instead of "printf"--missing character "t" */
//1.4 compiled, linked, ran correctly
//1.5 tested selection 1, Canada dollar, converted correctly $500 USD to 499.925 CAD
//1.6 tested selection 2, Indian Rupees, converted correctly $500 USD to 21,295 IR
//1.7 tested selection 3, Australian Dollar, converted correctly $500 USD to 523.75 AUS
//1.8 tested selection 4, Mexican Pesos, converted correctly $500 USD to 5203.1 MXN
//1.9 tested selection 5, Japanese Yen, converted correctly $500 USD to 52,040 JPY
[+][-]05.21.2008 at 02:52PM PDT, ID: 21619331

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 03:12PM PDT, ID: 21619485

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C Programming Language, Miscellaneous Programming
Tags: C
Sign Up Now!
Solution Provided By: evilrix
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.21.2008 at 03:34PM PDT, ID: 21619595

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 03:40PM PDT, ID: 21619627

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628