• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2719
  • Last Modified:

Currency Conversion

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
contesa
Asked:
contesa
3 Solutions
 
hongjunCommented:
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
 
hongjunCommented:
one thing to take note of is you need to have your function body outside the main.

hongjun
0
 
avizitCommented:
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
Increase Security & Decrease Risk with NSPM Tools

Analyst firm, Enterprise Management Associates (EMA) reveals significant benefits to enterprises when using Network Security Policy Management (NSPM) solutions, while organizations without, experienced issues including non standard security policies and failed cloud migrations

 
avizitCommented:
hongjun is faster than me :) but i see  he is in my same timezone ;)
0
 
hongjunCommented:
@avizit

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

hongjun
0
 
avizitCommented:
singapore too but from the "other" university not NUS. ;)
0
 
hongjunCommented:
@avizit,

Nice to know you :)

hongjun
0
 
avizitCommented:
@hongjun

same here :)

/abhijit/

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

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

hongjun
0
 
ankuratvbCommented:
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
 
contesaAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now