General discussion

Locked

Simple C Programming Question

By tturner33 ·
I am returning to school to complete my degree and I'm currently taking an Intro to C Programming class. For an assignment, we have to write a program that allows a user to select one of five choices of foreign currency and then convert it to US dollars. I have the program compiling without errors but it returns a conversion of $0.00. Can some one look at my code and tell me what I'm missing? The code is listed below (Sorry about the word-wraps). Thanks.

/* cur_conv.c - Currency Conversion Program Version 1.1 */
/* Currency Conversion data as of 12/03/04 */
/* Source data provided by http://finance.yahoo.com */

#include <stdio.h>
#define ARS 0.3356; /* Argentine Peso conversion rate */
#define GBP 1.9434; /* British Pound conversion rate */
#define EUR 1.3453; /* European Euro conversion rate */
#define CHF 0.8841; /* Swiss Franc conversion rate */
#define ZMK 0.0002; /* Zambian Kwacha conversion rate */
/* Main Program */
int main (void)
{
float usd;
float conversion;
float newrate;
int selection;
printf("This program will convert foreign currency to US Dollars\n");
printf("\n");
printf("Argentine Peso\t(ARS) * 0.3356 = USD\n"); /* First conversion rate */
printf("British Pound\t(GBP) * 1.9434 = USD\n"); /* Second conversion rate */
printf("European Euro\t(EUR) * 1.3453 = USD\n"); /* Third conversion rate */
printf("Swiss Franc\t(CHF) * 0.8841 = USD\n"); /* Fourth conversion rate */
printf("Zambian Kwacha\t(ZMK) * 0.0002 = USD\n\n"); /* Fifth conversion rate */


printf("Enter currency of your choice:\t[1] ARS\t[4] CHF\n"); /* Tabs entered for readability */
printf("\t\t\t\t[2] GBP\t[5] ZMK\n");
printf("\t\t\t\t[3] EUR ");
scanf("%d", &selection);

switch (selection) /* switch statements section */
{
case '1' : conversion = ARS; break;
case '2' : conversion = GBP; break;
case '3' : conversion = EUR; break;
case '4' : conversion = CHF; break;
case '5' : conversion = ZMK; break;
}

printf("Enter the amount of foreign currency to be converted ");
scanf("%f",&usd);

newrate = conversion * usd;
printf("\n");
printf("That amount in US Dollars is: $ %.2f\n", newrate);
return 0;
}

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Simple C Programming Question

by flytomanish In reply to Simple C Programming Ques ...

change case '1': to case 1:

Collapse -

what flytomanish said

by apotheon In reply to Simple C Programming Ques ...

Those single-quotes in the case statements need to be removed.

Collapse -

c programming

by kirbyantonio21 In reply to Simple C Programming Ques ...

please help me....please create a program that will display the exchange rate of peso to dollar <1dollar-50pesos...

Back to Desktop Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums