Solved

Currency Conversion

Posted on 2004-07-31
11
2,706 Views
Last Modified: 2012-05-05
I'm trying to code my first c program.........it looks like this is a common homework problem. I've researched other solutions and  yet I can figure out why mine isn't working....just want some suggestions on what I should be looking for. I keep getting a 'SEP' error on line 31...

/*this program shows currency coversions*/
#include <stdio.h>

/* currencies defined / rates equal to on US dollar */
#define Argentina_Pesos 2.95400
#define Canada_Dollars 1.32352
#define UK_Pounds 0.54382
#define HongKong_Dollars 7.79900
#define Japan_Yen 109.626

/* declare variables */

int AMOUNT = 0;
float Argentina= 2.95400;
float Canada= 1.32352;
float UK= 0.54382;
float HongKong= 7.79900;
float Japan=109.626;

/* function prototyping */

void fnDisplayMenu(int*);
void fnDollarAmount(int *);
float fnCalculateConversion(int,float);

int main()

{

/* function to display selection of currencies */

      void fnDisplayMenu(int *SELECTION)   /*This is the line that causes the compiler to stop*/

      {
            int selection;
            printf("Please select a currency exchange conversion:\n"); //Enter selection number for currency
            printf("Press [1] for Argentina Pesos\n");
            printf("Press [2] for Canada Dollar\n");
            printf("Press [3] for United Kingdom Pounds\n");
            printf("Press [4] for Hong Kong Dollars\n");
            printf("Press [5] for Japan Yen\n\n");
            scanf("%d",&selection);
            *SELECTION = selection;
            
      void fnDollarAmount(int *AMOUNT)                  
            printf(" Please enter a US Dollar Amount:\n\n ");  // Enter Dollar Amount
                scanf("%d",&amount);
            *AMOUNT = amount
      }

/* function to calculate conversion depending on selection by user */
      
       float fnCalculateConversion(int SELECTION, float AMOUNT)

      {
            float conversion;
            switch(SELECTION)
            
                  {
                  
                        case 1:
                              printf("Your Argentina Pesos equal $%.2f U.S. Dollars\n\n",conversion);
                              conversion = Argentina * AMOUNT;
                              break;
                        
                        case 2:
                              printf("Your Canada Dollars equal $%.2f U.S. Dollars\n\n",conversion);
                              conversion = Canada * AMOUNT;
                              break;
                              
                        case 3:
                              printf("Your United Kingdom Pounds equal $%.2f U.S. Dollars\n\n",conversion);
                              conversion = UK * AMOUNT;
                              break;
                              
                        case 4:
                        
                              printf("Your Hong Kong Dollars equal $%.2f U.S. Dollars\n\n",conversion);
                              conversion = HongKong * AMOUNT;
                              break;
                              
                        case 5:
                        
                              printf("Your Japan Yen equal $%.2f U.S. Dollars\n\n",conversion);
                              conversion = Japan * AMOUNT;
                              break;
                  }
                  
                  return conversion;
      
      
      }

return 0;

}
0
Comment
Question by:contesa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 33

Assisted Solution

by:hongjun
hongjun earned 200 total points
ID: 11686566
Try this



/*this program shows currency coversions*/
#include <stdio.h>

/* currencies defined / rates equal to on US dollar */
#define Argentina_Pesos 2.95400
#define Canada_Dollars 1.32352
#define UK_Pounds 0.54382
#define HongKong_Dollars 7.79900
#define Japan_Yen 109.626

/* declare variables */

float AMOUNT = 0;
float Argentina= 2.95400f;
float Canada= 1.32352f;
float UK= 0.54382f;
float HongKong= 7.79900f;
float Japan=109.626f;

/* function prototyping */

void fnDisplayMenu(int*);
void fnDollarAmount(int *);
float fnCalculateConversion(int,float);

int main()

{
    int selection;

    fnDisplayMenu(&selection);
    fnCalculateConversion(selection, AMOUNT);


    return 0;
   
}

/* function to display selection of currencies */

void fnDisplayMenu(int *SELECTION)   /*This is the line that causes the compiler to stop*/

{
    int selection;
    printf("Please select a currency exchange conversion:\n"); //Enter selection number for currency
    printf("Press [1] for Argentina Pesos\n");
    printf("Press [2] for Canada Dollar\n");
    printf("Press [3] for United Kingdom Pounds\n");
    printf("Press [4] for Hong Kong Dollars\n");
    printf("Press [5] for Japan Yen\n\n");
    scanf("%d",&selection);
    *SELECTION = selection;
   
    //void fnDollarAmount(int *AMOUNT)              
        printf(" Please enter a US Dollar Amount:\n\n ");  // Enter Dollar Amount
    scanf("%f",&AMOUNT);
    //*AMOUNT = amount
}

/* function to calculate conversion depending on selection by user */

float fnCalculateConversion(int SELECTION, float AMOUNT)

{
    float conversion=0;
    switch(SELECTION)
       
    {
       
    case 1:
        conversion = Argentina * AMOUNT;
        printf("Your Argentina Pesos equal $%.2f U.S. Dollars\n\n",conversion);
        break;
       
    case 2:
        conversion = Canada * AMOUNT;
        printf("Your Canada Dollars equal $%.2f U.S. Dollars\n\n",conversion);
        break;
       
    case 3:
        conversion = UK * AMOUNT;
        printf("Your United Kingdom Pounds equal $%.2f U.S. Dollars\n\n",conversion);
        break;
       
    case 4:
        conversion = HongKong * AMOUNT;
        printf("Your Hong Kong Dollars equal $%.2f U.S. Dollars\n\n",conversion);
        break;
       
    case 5:
        conversion = Japan * AMOUNT;
        printf("Your Japan Yen equal $%.2f U.S. Dollars\n\n",conversion);
        break;
    }
   
    return conversion;
   
   
}




hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 11686570
one thing to take note of is you need to have your function body outside the main.

hongjun
0
 
LVL 11

Assisted Solution

by:avizit
avizit earned 200 total points
ID: 11686573
1. in 'fnDollarAmount' there should be a '{' before the first line of the function statement
2. in 'fnDollarAmount' you need to declare 'amount'
3. you need a ';' at the end of  *AMOUNT = amount

4. your main function doesn't do anything ...i.e you have defined the functions there but you havent called any . yuo can do the following
move the function definitions out of main()  and call the functions from main as in

main(){

fnDisplayMenu( );
fnDollarAmount()
fnCalculateConversion()
}

don't forget to declare necessary variables and also pass the required arguments

---
come back after you make the above changes and we can proceed from there

/abhijit/


   





   
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:avizit
ID: 11686574
hongjun is faster than me :) but i see  he is in my same timezone ;)
0
 
LVL 33

Expert Comment

by:hongjun
ID: 11686577
@avizit

Where are you from? I am from Singapore! I see you also have got a gmail account :)

hongjun
0
 
LVL 11

Expert Comment

by:avizit
ID: 11686589
singapore too but from the "other" university not NUS. ;)
0
 
LVL 33

Expert Comment

by:hongjun
ID: 11686594
@avizit,

Nice to know you :)

hongjun
0
 
LVL 11

Expert Comment

by:avizit
ID: 11686605
@hongjun

same here :)

/abhijit/

ps: hope we are not violating EE policy by indulging in pvt talk.  btw signed your guestbook ;)
0
 
LVL 33

Expert Comment

by:hongjun
ID: 11686614
@avizit

Welcome to Singapore and may you enjoy your study here :)

hongjun
0
 
LVL 9

Accepted Solution

by:
ankuratvb earned 100 total points
ID: 11690876
Hi,

I guess the program code has been corrected by the previous comments.Just that the output message doesnt seem appropriate.

>>
Please select a currency exchange conversion:
Press [1] for Argentina Pesos
Press [2] for Canada Dollar
Press [3] for United Kingdom Pounds
Press [4] for Hong Kong Dollars
Press [5] for Japan Yen

1
 Please enter a US Dollar Amount:

 1
Your Argentina Pesos equal $2.95 U.S. Dollars
<<

You enter a US Dollar amount and you get the converted value in dollars again.

A more appropriate message'd be:
>Your U.S. Dollars equal $2.95 Argentina Pesos

:~)
0
 

Author Comment

by:contesa
ID: 11703529
Thank you all very much......actually I learned from you guys a lot (especially about the correct placement of functions and calling functions)...you were all great.

Thanks again.

I'm not finished with this problem...now I have to include an if statement.

I'm going to give it a whirl and see if I can get it going..if not, I'll be back (like Arnold would say)..

/contesa
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question