Solved

Error Monster are Here " currency conversion meun "

Posted on 2004-10-27
330 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
Question by:lclarius
    27 Comments
     
    LVL 23

    Expert Comment

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

    Author Comment

    by:lclarius
    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
    You still haven't defined ch anywhere.  Add

    int ch;

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


    0
     
    LVL 23

    Expert Comment

    by:cookre
    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
    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
    how do I convert ch to a char and use new variable for the switch
    0
     

    Author Comment

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

    Expert Comment

    by:brettmjohnson
    > 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
    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
    i know its expecting an bracket  that is what i'm getting out of the error .........
    0
     

    Author Comment

    by:lclarius
    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
    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
    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
    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
    >>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
    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
    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
    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
    I notice that you havent made the changes I suggested earlier. Didnt they work?

    Paul
    0
     

    Author Comment

    by:lclarius
    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
    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
    ok will do - lclarius
    0
     
    LVL 14

    Expert Comment

    by:Farzad Akbarnejad
    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:
    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
    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
    many thanks to Paul , George & FA thanks for having all the patients in the world
    lisa
    0
     
    LVL 16

    Expert Comment

    by:PaulCaswell
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    875 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