Need dome help with my code. It is a simple C program to prompt a user to enter an anout of US Dollar and it will convert it to a currency selected. I have the main() function and one function that passes a variable by reference and one by variable. It seems the reference function works as it up brings up the menu and allows the user to pick a currency. Whne it call the value function is where I think the problem is. The program outputs 0.00 at the end in stead of the proper converted value. Here is the code:
/*include the library*/
#include <stdio.h>
/*define the five currencies used for the conversion*/
#define Currency1 0.58
#define Currency2 2.50
#define Currency3 3.69
#define Currency4 21.00
#define Currency5 1.75
/*function prototyping*/
void menu (int *);
float calculateConversion(int, float);
/*main function of the program*/
int main()
{
/*declare variables*/
float us;
float conversion;
int choice;
/*call user selection menu by reference*/
menu(&choice);
/*prompt user to enter amount of US to convert*/
printf("Please enter an amount in US Dolalrs to convert: $");
/*store user entry into memeory*/;
scanf("%f",us);
/*call conversion function by value*/
calculateConversion (choice, us);
/*print results of conversion*/
printf("The amount of that currency in US Dollars is: $%.2f\n", conversion);
/*display results*/
getchar();
/*terminate program*/
return 0;
}
/*function definition by reference*/
void menu(int *CHOICE)
{
/*local variables for menu()*/
int choice;
/*show options to user*/
printf("Welcome to the currency conversion program\n");
printf("Press number 1 to 5 to select a currency to convert\n");
printf("Press [1] for Pounds\n");
printf("Press [2] for Deutchmarks\n");
printf("Press [3] for Francs\n");
printf("Press [4] for Pesetas\n");
printf("Press [5] for Canadian Dollars\n");
/*store choice in memory*/
scanf("%d", &choice);
/*set value of referenced variable*/
*CHOICE = choice;
}
/*function definition by value*/
float calculateConversion(int CHOICE, float us)
{
/*local variable for conversion*/
float conversion;
/*switch to user the case selected by user in reference funtion*/
switch (CHOICE)
{
case 1:
conversion=Currency1*us;
break;
case 2:
conversion=Currency2*us;
break;
case 3:
conversion=Currency3*us;
break;
case 4:
conversion=Currency4*us;
break;
case 5:
conversion=Currency5*us;
break;
}
/*returns the new value to the main function*/
return conversion;
}