Error Monster are Here " currency conversion meun "

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");

}

}

}
lclariusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cookreCommented:
I sure don't see where it's defined.
0
lclariusAuthor Commented:
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
brettmjohnsonCommented:
You still haven't defined ch anywhere.  Add

int ch;

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


0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

cookreCommented:
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
lclariusAuthor Commented:
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
lclariusAuthor Commented:
how do I convert ch to a char and use new variable for the switch
0
lclariusAuthor Commented:
guys i'm in need of your help please
0
brettmjohnsonCommented:
> 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
lclariusAuthor Commented:
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
lclariusAuthor Commented:
i know its expecting an bracket  that is what i'm getting out of the error .........
0
lclariusAuthor Commented:
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
lclariusAuthor Commented:
There was error parsing your query.
c is not valid field. The following are valid fields: title body content
0
PaulCaswellCommented:
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
Farzad AkbarnejadDeveloperCommented:
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
PaulCaswellCommented:
>>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
georg74Commented:
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
lclariusAuthor Commented:
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
PaulCaswellCommented:
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
PaulCaswellCommented:
I notice that you havent made the changes I suggested earlier. Didnt they work?

Paul
0
lclariusAuthor Commented:
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
PaulCaswellCommented:
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
lclariusAuthor Commented:
ok will do - lclarius
0
Farzad AkbarnejadDeveloperCommented:
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
georg74Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lclariusAuthor Commented:
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
lclariusAuthor Commented:
many thanks to Paul , George & FA thanks for having all the patients in the world
lisa
0
PaulCaswellCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

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.