Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Error Monster are Here " currency conversion meun "

Posted on 2004-10-27
27
Medium Priority
?
430 Views
Last Modified: 2010-04-17
I'm getting an error on Miracle C Compiler (r3.2), written by bts.

C:\Program Files\Miracle C\Currencyconvlisaclariusweekfive.c: line 56: variable 'ch' not found
'ch=getch()'
aborting compile



#include <stdio.h>              /*Currency Converison Menu */
void  main(void)      
{                        /*beginning functionality*/ //Display five foreign currencies for one US Dollar //

float AUD,CAD,EUR,GBP,MXN,US;

       AUD=1.40193f;
       GBP=0.52334f;
       CAD=1.2754f;
       EUR=0.812612f;
       MXN=11.405f;
      US=1.00f;
      
printf("Currency Conversion\n\n");      
    printf("%f Austrialia Dollar is equivalent to %f US Dollar\n",AUD,US);
    printf("%f Canadian Dollars is equivalent to %f US Dollar\n",CAD,US);
    printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
    printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
    printf("%f Mexican Pesos is equivalent to %f US Dollar\n",MXN,US);
{char repeat = ('n');
getch();   /* WAITS UNTIL A KEY IS PRESSED, getch() WAIT FOR A KEY AND TELLS YOU WHICH */
}
convert();  
           
printf("Select a currency type\n\n");
printf("1=Austrialia Dollar 2=United Kingdom Pound 3= Canadian Dollar 4=European Euro 5=Mexican Pesos\n");
printf("Select the 4=Canadian Dollars currency type\n\n");
{
int AUD,CAD,GBP,EUR,MXN,US;
       AUD=1;
       CAD=2;
       GBP=3;
      EUR=4;
          MXN=5;


// Display and print //
           printf("You selected something other than 1 to 5");
         printf("Validate input for USdollar amount\n");
         printf("Dollar amount must be between .01 to 1000.00. \n");

ch=getch();

switch(ch) //is the best thing to use for menu driven programs
{
case '1':
            printf("You selected 1\n");
            break;

case '2':
            printf("You selected 2\n");
            break;

case '3':
            printf("You selected 3\n");
            break;

case '4':
            printf("You selected 4\n");
            break;

case '5':
            printf("You selected 5\n");
            break;

default:
           printf("You selected something other than 1 to 5");

}

}

}
0
Comment
Question by:lclarius
[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
  • 13
  • 6
  • 2
  • +3
27 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 12430157
I sure don't see where it's defined.
0
 

Author Comment

by:lclarius
ID: 12430352
that could very well be the reason ..........
i'm assuming that your refering to declaring - I'm still getting error see below

Miracle C Compiler (r3.2), written by bts.

C:\Program Files\Miracle C\Currencyconvlisaclariusweekfive.c: line 60: variable 'ch' not found
'ch=getch()'
aborting compile

 #include <stdio.h>              /*Currency Converison Menu */
int  main(void)      
{                      

//Declare main function variables and initalize as needed

 /*beginning functionality*/ //Display five foreign currencies for one US Dollar //

float AUD,CAD,EUR,GBP,MXN,US;

       AUD=1.40193f;
       GBP=0.52334f;
       CAD=1.2754f;
       EUR=0.812612f;
       MXN=11.405f;
      US=1.00f;
      
printf("Currency Conversion\n\n");      
    printf("%f Austrialia Dollar is equivalent to %f US Dollar\n",AUD,US);
    printf("%f Canadian Dollars is equivalent to %f US Dollar\n",CAD,US);
    printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
    printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
    printf("%f Mexican Pesos is equivalent to %f US Dollar\n",MXN,US);
{char repeat = ('n');
getch();   /* WAITS UNTIL A KEY IS PRESSED, getch() WAIT FOR A KEY AND TELLS YOU WHICH */
}
convert();  
           
printf("Select a currency type\n\n");
printf("1=Austrialia Dollar 2=United Kingdom Pound 3= Canadian Dollar 4=European Euro 5=Mexican Pesos\n");
printf("Select the 4=Canadian Dollars currency type\n\n");
{
int AUD,CAD,GBP,EUR,MXN,US;
       AUD=1;
       CAD=2;
       GBP=3;
      EUR=4;
          MXN=5;


// Display and print //
           printf("You selected something other than 1 to 5");
         printf("Validate input for USdollar amount\n");
         printf("Dollar amount must be between .01 to 1000.00. \n");

ch=getch();

switch(ch) //is the best thing to use for menu driven programs
{
case '1':
            printf("You selected 1\n");
            break;

case '2':
            printf("You selected 2\n");
            break;

case '3':
            printf("You selected 3\n");
            break;

case '4':
            printf("You selected 4\n");
            break;

case '5':
            printf("You selected 5\n");
            break;

default:
           printf("You selected something other than 1 to 5");

}

}

}


AUS=(1);
if EUR==4);
{
else if (GBP==3);
else if (AUD==1);
else if (CAD==2);
else if (MXN==5);
}
printf("Number 1 Canadian Dollars has been selected\n\n");

float AUD,CAD,GBP,EUR,MXN,US;  

          AUD=1.40193f;
       GBP=0.52334f;
       CAD=1.2754f;
       EUR=0.812612f;
       MXN=11.405f;
      US=1.00f;
      
  printf("The selected currency type is the Canadian dollar of %f equivlwnt to %f US Dollar\n"CAD,US};

 //Display title page and date of conversion //
 printf("Currency Conversion\n");    /* Title of Currency Exchange Rates    */
 printf("October 13,2004\n");     /* Date of Currency Exchange Rates     */  
 printf("\n"); /*Blank line */
   

getch();
return 0;                          
}            /*THE END*/


      
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12430428
You still haven't defined ch anywhere.  Add

int ch;

somewhere in scope before you use it (as the recipient to getch()).


0
Technology Partners: 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 22

Expert Comment

by:cookre
ID: 12430441
Yup.  Since getch() is typed as int, stick in a:

int ch;

and change you cases to ints, or convert ch to a char and use that new variable for the switch.
0
 

Author Comment

by:lclarius
ID: 12430515
ok , i have added int ch; before using getch (ch)
however i don't understand what your telling me to do in case
could you clarify for me please ---- i'm new at C and learning would like to understand please help lclarius

#include <stdio.h>              /*Currency Converison Menu */
int  main(void)      
{                      

//Declare main function variables and initalize as needed

 /*beginning functionality*/ //Display five foreign currencies //

 
float AUD,CAD,EUR,GBP,MXN,US;

       AUD=1.40193f;
       GBP=0.52334f;
       CAD=1.2754f;
       EUR=0.812612f;
       MXN=11.405f;
      US=1.00f;
      
printf("Currency Conversion\n\n");      
    printf("%f Austrialia Dollar is equivalent to %f US Dollar\n",AUD,US);
    printf("%f Canadian Dollars is equivalent to %f US Dollar\n",CAD,US);
    printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
    printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
    printf("%f Mexican Pesos is equivalent to %f US Dollar\n",MXN,US);
{char repeat = ('n');
getch();   /* WAITS UNTIL A KEY IS PRESSED, getch() WAIT FOR A KEY AND TELLS YOU WHICH */
}
convert();  
           
printf("Select a currency type\n\n");
printf("1=Austrialia Dollar 2=United Kingdom Pound 3= Canadian Dollar 4=European Euro 5=Mexican Pesos\n");
printf("Select the 4=Canadian Dollars currency type\n\n");
{
int AUD,CAD,GBP,EUR,MXN,US;
       AUD=1;
       CAD=2;
       GBP=3;
      EUR=4;
          MXN=5;


// Display and print //
           printf("You selected something other than 1 to 5");
         printf("Validate input for USdollar amount\n");
         printf("Dollar amount must be between .01 to 1000.00. \n");
        
int ch;
ch=getch();

switch(ch) //is the best thing to use for menu driven programs
{
case '1':
            printf("You selected 1\n");
            break;

case '2':
            printf("You selected 2\n");
            break;

case '3':
            printf("You selected 3\n");
            break;

case '4':
            printf("You selected 4\n");
            break;

case '5':
            printf("You selected 5\n");
            break;

default:
           printf("You selected something other than 1 to 5");

}

}

}


AUS=(1);
if EUR==4);
{
else if (GBP==3);
else if (AUD==1);
else if (CAD==2);
else if (MXN==5);
}
printf("Number 1 Canadian Dollars has been selected\n\n");

float AUD,CAD,GBP,EUR,MXN,US;  

          AUD=1.40193f;
       GBP=0.52334f;
       CAD=1.2754f;
       EUR=0.812612f;
       MXN=11.405f;
      US=1.00f;
      
  printf("The selected currency type is the Canadian dollar of %f equivlwnt to %f US Dollar\n"CAD,US};

 //Display title page and date of conversion //
 printf("Currency Conversion\n");    /* Title of Currency Exchange Rates    */
 printf("October 13,2004\n");     /* Date of Currency Exchange Rates     */  
 printf("\n"); /*Blank line */
   

getch();
return 0;                          
}            /*THE END*/
0
 

Author Comment

by:lclarius
ID: 12430574
how do I convert ch to a char and use new variable for the switch
0
 

Author Comment

by:lclarius
ID: 12430632
guys i'm in need of your help please
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12430652
> how do I convert ch to a char and use new variable for the switch

switch() expects an int as an argument.
getch() and getchar() return an int.
chars, when assigned to an int, are automatically converted to int.

In other words, you don't have to do anything.

0
 

Author Comment

by:lclarius
ID: 12430858
ok i get the jif of this but my code is throwing off this error.......
i'm confused very ........ please have patients with me ...... cause i want to pull my hair out :(
Miracle C Compiler (r3.2), written by bts.

C:\Program Files\Miracle C\Currencyconvlisaclariusweekfive.c: line 61: Parse Error, expecting `'}''
'int ch'
aborting compilee jif of that - my code is throwing off this error
0
 

Author Comment

by:lclarius
ID: 12430874
i know its expecting an bracket  that is what i'm getting out of the error .........
0
 

Author Comment

by:lclarius
ID: 12430887
i can't go to bed without working this out ........ i'm on cst here1:46 needing help with understanding ......how to correct this mess i'm in ............lclarius
0
 

Author Comment

by:lclarius
ID: 12430951
There was error parsing your query.
c is not valid field. The following are valid fields: title body content
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 12431234
This is 'C', not C++ so you have to declare after a '{'.

use:

int AUD,CAD,GBP,EUR,MXN,US,ch;

I hope you got to bed. ;)

Next time, post 'C' questions in the 'C' area. You'll get a quicker response.

Paul
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 12431797
Hello,
Post your source file here. I must compile it. I think that there are some mistakes in it.
in C you must declare variables at the start of function.

Thanks
-FA
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 12433993
>>in C you must declare variables at the start of function.
Not quite!! Its actually at the start of a block.

E.G.. You CAN do:

...
for ( i = 0; i < 10; i++ )
{
  int x = 128;

  ...
}


Paul
0
 
LVL 3

Expert Comment

by:georg74
ID: 12434841
hi lclarius,

the code you posted has has several bugs / problems.
actually, it is quite messed up. please write what kind of help do you want.
do you want just to get the code running or to understand what needs to be
corrected and how?

good luck,
georg
0
 

Author Comment

by:lclarius
ID: 12435682
here is what the program should do

1. Present a menu of currencies with one choice to end the program.
2. On a currency choice ask $US you want to convert or 0 to return to the menu.
3. Here you might have a few choices
    a. Loop around the $US choice, allowing a repeat of $US dollar amounts, invalid values with error messages and only exiting back to the menu on a 0 value.
    b. One response only, display conversion if valid amount, display error message if not valid, return to menu on 0, but in all three choices return to menu as you are only allowing one currency conversion per menu choice.
4. Repeat 1




#include <stdio.h>              /*Currency Converison Menu */
void  main(void)      
{                      

//Declare main function variables and initalize as needed

 /*beginning functionality*/ //Display five foreign currencies //

      char ch;
 
float AUD,CAD,EUR,GBP,MXN,US;

       AUD=1.40193f;
       GBP=0.52334f;
       CAD=1.2754f;
       EUR=0.812612f;
       MXN=11.405f;
      US=1.00f;
      
printf("Currency Conversion\n\n");      
    printf("%f Austrialia Dollar is equivalent to %f US Dollar\n",AUD,US);
    printf("%f Canadian Dollars is equivalent to %f US Dollar\n",CAD,US);
    printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
    printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
    printf("%f Mexican Pesos is equivalent to %f US Dollar\n",MXN,US);

getch();   /* WAITS UNTIL A KEY IS PRESSED, getch() WAIT FOR A KEY AND TELLS YOU WHICH */

convert();  /*
           
printf("Select a currency type\n\n");
printf("1=Austrialia Dollar 2=United Kingdom Pound 3= Canadian Dollar 4=European Euro 5=Mexican Pesos\n");
printf("Select the 4=Canadian Dollars currency type\n\n");
{
int AUD,CAD,GBP,EUR,MXN,US;
       AUD=1;
       CAD=2;
       GBP=3;
      EUR=4;
    MXN=5;


// Display and print //
       printf("You selected something other than 1 to 5");
         printf("Validate input for USdollar amount\n");
         printf("Dollar amount must be between .01 to 1000.00. \n");
        
char option /* using variable to obtain key pressed */  

}
ch=getch();

switch(ch) //is the best thing to use for menu driven programs
{
case '1':
            printf("You selected 1\n");
            break;

case '2':
            printf("You selected 2\n");
            break;

case '3':
            printf("You selected 3\n");
            break;

case '4':
            printf("You selected 4\n");
            break;

case '5':
            printf("You selected 5\n");
            break;

default:
           printf("You selected something other than 1 to 5");

}

}

}


AUS=(1);
if EUR==4);
{
else if (GBP==3);
else if (AUD==1);
else if (CAD==2);
else if (MXN==5);
}
printf("Number 1 Canadian Dollars has been selected\n\n");

float AUD,CAD,GBP,EUR,MXN,US;  

          AUD=1.40193f;
       GBP=0.52334f;
       CAD=1.2754f;
       EUR=0.812612f;
       MXN=11.405f;
      US=1.00f;
      
  printf("The selected currency type is the Canadian dollar of %f equivlwnt to %f US Dollar\n"CAD,US};

 //Display title page and date of conversion //
 printf("Currency Conversion\n");    /* Title of Currency Exchange Rates    */
 printf("October 28,2004\n");     /* Date of Currency Exchange Rates     */  
 printf("\n"); /*Blank line */
   

getch();
return 0;                          
{            /*THE END*/
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 12435743
I'd suggest you re-read georg's comment.

We cannot fix your code as this is homework, we can only help you fix it.

Paul
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 12435767
I notice that you havent made the changes I suggested earlier. Didnt they work?

Paul
0
 

Author Comment

by:lclarius
ID: 12435805
Miracle C Compiler (r3.2), written by bts.
Compiling C:\Program Files\Miracle C\currencyconversionlisaclariusweekfive1.c
main

Compiler internal error
(cc.y, 2373) C:\Program Files\Miracle C\currencyconversionlisaclariusweekfive1 : 51: call outside proc
Please report the above message with your source code to the author
'ch=getch()'

i'm getting this errror - i really need to know how to correct code so it will  compile, build and execute
thanks guys lclarius
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 12435860
The trick to getting it all to compile is to remove most of the code and slowly insert it back until something goes wrong.

I'd suggest you start with:

#include <stdio.h>              /*Currency Converison Menu */
void  main(void)      
{                      

//Declare main function variables and initalize as needed

 /*beginning functionality*/ //Display five foreign currencies //

     char ch;
 
float AUD,CAD,EUR,GBP,MXN,US;

      AUD=1.40193f;
      GBP=0.52334f;
      CAD=1.2754f;
      EUR=0.812612f;
      MXN=11.405f;
     US=1.00f;
     
printf("Currency Conversion\n\n");      
    printf("%f Austrialia Dollar is equivalent to %f US Dollar\n",AUD,US);
    printf("%f Canadian Dollars is equivalent to %f US Dollar\n",CAD,US);
    printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
    printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
    printf("%f Mexican Pesos is equivalent to %f US Dollar\n",MXN,US);

getch();   /* WAITS UNTIL A KEY IS PRESSED, getch() WAIT FOR A KEY AND TELLS YOU WHICH */

}

and slowly add the rest bit by bit.

Paul
0
 

Author Comment

by:lclarius
ID: 12435897
ok will do - lclarius
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 12436110
1. if EUR==4);         Change To ==>    if (EUR==4)

2. Change

printf("The selected currency type is the Canadian dollar of %f equivlwnt to %f US Dollar\n"CAD,US};

to

printf("The selected currency type is the Canadian dollar of %f equivlwnt to %f US Dollar\n",CAD,US);

You used } instead of ) and forgot , character

3. You declared AUD, ... variables as float once and later declared them as int. You can't redefine variables in one scope.
Change the name of second group variables to start with i such as iAUD,....


-FA




0
 
LVL 3

Accepted Solution

by:
georg74 earned 2000 total points
ID: 12436676
I agree with Paul, with a slight change in the code you're starting with:
put
      float AUD,CAD,EUR,GBP,MXN,US;

after #include lines, in front of all other functions. this way they will
be global variables accessible from all following functions.

georg
0
 

Author Comment

by:lclarius
ID: 12436959
Guys YOU ARE THE BEST .....I surly didnot want to go global however it worked

Compiled
Built
and Executed - this is what code produce in DOS

Currency Conversion

1.401930 Austrialia Dollar is equivalent to 1.000000 US Dollar
1.275400 Canadian Dollars is equivalent to 1.000000 US Dollar
0.523340 United Kingdom Pound is equivalent to 1.000000 US Dollar
0.812612 European Euro is equivalent to 1.000000 US Dollar
11.405000 Mexican Pesos is equivalent to 1.000000 US Dollar




#include <stdio.h>              /*Currency Converison Menu */

/* Declaring  and intalizing Global variables*/

 float AUD,CAD,EUR,GBP,MXN,US;


void  main(void)      
{                      

//Declare main function variables and initalize as needed

 /*beginning functionality*/ //Display five foreign currencies //

     char ch;
 

      AUD=1.40193f;
      GBP=0.52334f;
      CAD=1.2754f;
      EUR=0.812612f;
      MXN=11.405f;
      US=1.00f;
     
printf("Currency Conversion\n\n");      
    printf("%f Austrialia Dollar is equivalent to %f US Dollar\n",AUD,US);
    printf("%f Canadian Dollars is equivalent to %f US Dollar\n",CAD,US);
    printf("%f United Kingdom Pound is equivalent to %f US Dollar\n",GBP,US);
    printf("%f European Euro is equivalent to %f US Dollar\n",EUR,US);
    printf("%f Mexican Pesos is equivalent to %f US Dollar\n",MXN,US);

getch();   /* WAITS UNTIL A KEY IS PRESSED, getch() WAIT FOR A KEY AND TELLS YOU WHICH */

}
0
 

Author Comment

by:lclarius
ID: 12436993
many thanks to Paul , George & FA thanks for having all the patients in the world
lisa
0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 12442183
Errm... I think you may have been a bit hasty.

Re-read my post and you will see:

>>... and slowly insert it back until something goes wrong.

What you have now does nothing. You meed to add more stuff to make it:

1. Ask for an amount.
2. Convert it.
3. Print the result.

Sadly, you've accepted an answer so I'd suggest you repost.

Paul
0

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.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

604 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