D
Dr_Z2A
Ok so a couple months ago I wrote a currency converter and never got it
to compile (my memorization of syntax sucked then) and I just had the
printed out copy lying in a stack of papers. So I found it the other
day and decided to fix it up. I have one problem that I can't figure
out in it still. When I run the program it prompts for the option
number as it is supposed to, but when I enter in the number it outputs
that I have entered an invalid option, so I figure my problem is in the
scanf or switch statement in the main function. Can anyone enlighten
me as to what I have done wrong? Heres the source code:
/* currency changer by Dr. Z2A July 25 2005 */
#include <stdio.h>
/*declare functions */
void euro();
void sfranc();
void pound();
/* main function */
main()
{
int c;
printf("welcome to the Dr. Z2A currency changer\n");
printf("Note that this changer is accurate as of July 25 2005 and may
be inaccurate if used in the future\n");
printf("To calculate dollars to euros press 1\n");
printf("To calculate dollars to swiss francs press 2\n");
printf("To calculate dollars to british pounds press 3\n");
scanf("%d",&c);
/* switch branch */
switch (c) {
case '1':
euro();
case '2':
sfranc();
case '3':
pound();
default:
printf("invalid option\n");
}
printf("Thank you for using the currency changer\n");
return 0;
}
/* other function definitions */
void euro()
{
double d,e; /* d for dollars, e for euro */
printf("Enter the amount of Euros that you would like to convert: ");
scanf("%f",e);
d = e * 0.832185; /* assign value of d */
printf("The value in dollars is %f",d);
}
void sfranc()
{
double d,f;
printf("Enter the amount of Swiss Francs that you would like to
convert: ");
scanf("%f",f);
d = f * 1.29979;
printf("The value in dollars is %f",d);
}
void pound()
{
double d,p;
printf("Enter the amount of British Pounds that you would like to
convert: ");
scanf("%f",p);
d = p * 0.5757;
printf("The value in dollars is %f",d);
}
to compile (my memorization of syntax sucked then) and I just had the
printed out copy lying in a stack of papers. So I found it the other
day and decided to fix it up. I have one problem that I can't figure
out in it still. When I run the program it prompts for the option
number as it is supposed to, but when I enter in the number it outputs
that I have entered an invalid option, so I figure my problem is in the
scanf or switch statement in the main function. Can anyone enlighten
me as to what I have done wrong? Heres the source code:
/* currency changer by Dr. Z2A July 25 2005 */
#include <stdio.h>
/*declare functions */
void euro();
void sfranc();
void pound();
/* main function */
main()
{
int c;
printf("welcome to the Dr. Z2A currency changer\n");
printf("Note that this changer is accurate as of July 25 2005 and may
be inaccurate if used in the future\n");
printf("To calculate dollars to euros press 1\n");
printf("To calculate dollars to swiss francs press 2\n");
printf("To calculate dollars to british pounds press 3\n");
scanf("%d",&c);
/* switch branch */
switch (c) {
case '1':
euro();
case '2':
sfranc();
case '3':
pound();
default:
printf("invalid option\n");
}
printf("Thank you for using the currency changer\n");
return 0;
}
/* other function definitions */
void euro()
{
double d,e; /* d for dollars, e for euro */
printf("Enter the amount of Euros that you would like to convert: ");
scanf("%f",e);
d = e * 0.832185; /* assign value of d */
printf("The value in dollars is %f",d);
}
void sfranc()
{
double d,f;
printf("Enter the amount of Swiss Francs that you would like to
convert: ");
scanf("%f",f);
d = f * 1.29979;
printf("The value in dollars is %f",d);
}
void pound()
{
double d,p;
printf("Enter the amount of British Pounds that you would like to
convert: ");
scanf("%f",p);
d = p * 0.5757;
printf("The value in dollars is %f",d);
}