GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Jun-2004, 14:57
mutt mutt is offline
New Member
 
Join Date: Jun 2004
Posts: 2
mutt is on a distinguished road

C Currency Conversion program help needed


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:

CPP / C++ / C 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;
}
  #2  
Old 13-Jun-2004, 15:14
mutt mutt is offline
New Member
 
Join Date: Jun 2004
Posts: 2
mutt is on a distinguished road
disregard, got it to work. had to add conversion= before right befoe the currencyConversion call. Also needed the & before us in the scanf line.
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with a C program (Long) McFury C Programming Language 3 29-Apr-2004 20:06
Modify a C program ayoub C Programming Language 3 15-Mar-2004 11:34
error during program rjd72285 C++ Forum 0 11-Nov-2003 18:49
one program access another? dgoulston C++ Forum 1 07-Oct-2003 11:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:13.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.