[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Menu Currency Conversion

Posted on 2004-10-26
18
Medium Priority
?
298 Views
Last Modified: 2010-04-15
 Present a menu of currencies with one choice to end the program.
 On a currency choice ask $US you want to convert or 0 to return to the menu.
  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.
  Repeat 1



Display a menu of currencies with one choice to end the program
menuChoice 1 - 5
   1. British  0.558378;
   2.Canadian   1.2914;
   3.European 0.822774;
   4.Australian  1.43102;
   5.Mexican 11.5055;
  99.  End menu;



I'm lost .... needing some tutorial please please I can usually get this but I burnt out today
 i know this a bit to ask ---- but can you help out here .......... I need help ..........

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
  • 10
  • 6
18 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 12416862
Hi lclarius,

This is a popular posting here at EE.  It's a pretty common homework assignment.

As homework, we can give you only limited direction and support.  You'll need to do the work.  I'll be glad to steer you in the right direction, but from then on you'll need to ask specific questions.

The first thing that you'll need to do is print the menu.

  printf ("  1.  Convert to British Pounds.\n");
  other choices go here.
  printf ("  0.  Exit.\n");

You should probably accept input via the fgets() or fscanf() function.  They'll read from the keyboard if you pass *stdin* as the file to be read.

Once you read the choice, verify that it is a legal option.  If so, use a switch() statement to control the program flow to select the correct conversion.

Print out the result, and loop back to the top.  You'll loop back because all of the code is enclosed in a while() statement.


This is the basic layout.  Give it a try and if you get stuck, post your question for more help.

Good Luck,
Kent
0
 

Author Comment

by:lclarius
ID: 12417081
Kent, thanks will do the work from your starting point, and post for clarification if ok
thanks a million lclairus
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 12417300
lclarius,

That's perfect.  :)  


Kent
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:lclarius
ID: 12429698
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");

}

}

}


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: 12429890
Please help I need to know why???
0
 

Author Comment

by:lclarius
ID: 12430315
is someone available to help me out here please, please  Mr or Ms Please
0
 

Author Comment

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

Expert Comment

by:Kent Olsen
ID: 12432567
Sorry Iclarius,  I missed your posts...

In this section, you reference the variabl "ch" and haven't defined it.

// 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();



After main(), just add the declaration, like this:

void  main(void)      
{                        /*beginning functionality*/ //Display five foreign currencies for one US Dollar //

  char ch;



Good Luck,
Kent
0
 

Author Comment

by:lclarius
ID: 12436810
kent i'm getting this error

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()'

 #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
 

Author Comment

by:lclarius
ID: 12436834
kent should i just start over seems this program is very upset with me ........ :) lisa
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 12437035
Hi Lisa,

Heck, if upset were any REAL criterion for abandonment, I'd have been left long ago... :)

Based on your last post, there are a couple of really obvious things that need to be corrected.  For someone that's comfortable with C it should only take about a minute to go through the source and clean it up.  So you're closer to getting a clean compile than you might think.

About 1/3 the way into the program source, you call convert().  The line ends with '/*'.  This is a "start of comment" marker that relegates everything as a comment until a '*/' is encountered.  The next comment is:

char option /* using variable to obtain key pressed */  

The end-of-comment marker on this line is actually ending the comment on the convert() statement line.  (The '/*' on this line is just considered part of the comment.)

The next line after "char option /* using variable to obtain key pressed */ " is a '}', followed by the "ch=getch()" text that the compiler is complaining about.

You need to remove the start-of-comment from the convert() line.  However, more problems will ensue as it looks like there is considerable cleanup to be done in the code that's commented out.  Start by taking the '/*' off the line and compiling.  We'll see what falls out next.


Kent
0
 

Author Comment

by:lclarius
ID: 12437196
ok going to give this a shot lisa
0
 

Author Comment

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

C:\Program Files\Miracle C\currencyconversionlisaclariusweekfive1.c: line 48: Parse Error, expecting `'}''
'char option     } ch=getch()'
aborting compile

took the '/*' and this error above is what I got

 #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 46

Accepted Solution

by:
Kent Olsen earned 2000 total points
ID: 12437861
Hi Lisa,

This really is a mess.  :(    But you've made a real effort and I can see why you're confused.  :)


I've reworked what you've already done.  Mostly, I've just discarded a bunch of stuff that you don't need.  It looks like you've tried several new ideas without discarding the old ones, or the editor burped on your code.

The only "changes" that I've made are to move some of the variables outside of the main() function into global storage, and to define some of the values as constants instead of variables.  The code compiles now, but it's obviously not done.  You probably want to include loop controls around the main body so that you can convert several things without rerunning the program.  And you need to do the conversions.  (Pretty easy, though.)

Take a look, and give it a try.  Write back if you get stuck again.

Oh.  And one really BIG suggestion -- indent.  It's a lot easier to keep track of all of the '{', '}' blocks with proper indentation.

Kent


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

#define iAUD 1
#define iCAD 2
#define iGBP 3
#define iEUR 4
#define iMXN 5

float fAUD=1.40193f,
      fGBP=0.52334f,
      fCAD=1.2754f,
      fEUR=0.812612f,
      fMXN=11.405f,
      fUS=1.00f;

int  main(void)
{

//Declare main function variables and initalize as needed

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

    char ch;

    printf("Currency Conversion\n\n");
    printf("%f Austrialia Dollar is equivalent to %f US Dollar\n", iAUD, fUS);
    printf("%f Canadian Dollars is equivalent to %f US Dollar\n", iCAD, fUS);
    printf("%f United Kingdom Pound is equivalent to %f US Dollar\n", iGBP, fUS);
    printf("%f European Euro is equivalent to %f US Dollar\n", iEUR, fUS);
    printf("%f Mexican Pesos is equivalent to %f US Dollar\n", iMXN, fUS);

    convert();

    printf("Select a currency type\n\n");

// 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() - '0';   // Trust me on this one :)

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

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

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

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

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

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

    }

//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
 

Author Comment

by:lclarius
ID: 12438011
Miracle C Compiler (r3.2), written by bts.
line   3: #include conio.h ignored--file not found.
Compiling C:\Program Files\Miracle C\wk5ialisa.c

C:\Program Files\Miracle C\wk5ialisa.c: line 1: cannot declare as undefined type
'include <stdlib.h>  typedef unsigned int size_t'
aborting compile

Well here we go again ,,, its the devil i know it is .......:)
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 12438123

Nahhhh....   My first wife already has that title.  ;)

You can delete the line '#include <conio.h>'.  My compiler requires it and I wanted to make sure that it compiled before returning it to you.

stdlib.h is a problem.  And a mystery.  Try deleting the line and compiling.  If that doesn't help we'll dig further.


Kent
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

650 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