Solved

Currency Conversion

Posted on 2004-07-31
11
2,689 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
11 Comments
 
LVL 33

Assisted Solution

by:hongjun
hongjun earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 11

Expert Comment

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

Expert Comment

by:hongjun
Comment Utility
@avizit

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

hongjun
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 11

Expert Comment

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

Expert Comment

by:hongjun
Comment Utility
@avizit,

Nice to know you :)

hongjun
0
 
LVL 11

Expert Comment

by:avizit
Comment Utility
@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
Comment Utility
@avizit

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

hongjun
0
 
LVL 9

Accepted Solution

by:
ankuratvb earned 100 total points
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now