Solved

Chose exit option to quit the program

Posted on 2004-08-18
9
341 Views
Last Modified: 2010-04-15
How would I enter in a exit option to quit this program? Thanks

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>                            
int main(void)
{

int EUR,GBP,JPY,CAD,RUR,US;  
float fCAD,fEUR,fGBP,fJPY,fRUR,fUS;
char option;
   EUR=1;
   GBP=2;
   JPY=3;
   CAD=4;
   RUR=5;
 
   
   fEUR=0.829643f;              
   fGBP=0.548242f;
   fJPY=110.631f;
   fCAD=1.31751f;
   fRUR=29.1800f;                                                                                  
    fUS=1.00f;
   printf("Select a currency type\n\n");
   printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
   printf("Select the 4=Canadian Dollars currency type\n\n");

while(1){

printf("Enter your choice:");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalent to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalent to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalent to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian Dollars of %f equivalent to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalent to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
scanf("%c", &option);
option=getch();

}
}
getch();
return 0;                          
}
0
Comment
Question by:RebeccaFusco
[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
  • 5
  • 4
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11834004
You already have one:

case '0':
printf("exiting...\n");
return (0);
0
 

Author Comment

by:RebeccaFusco
ID: 11834213
I was trying to make it say that the program was exiting if a number was not chosen.  Is that an option? Thanks
0
 
LVL 86

Expert Comment

by:jkr
ID: 11834417
Just use

/*Select a currency conversion type by code number 8/11/04*/
#include <stdio.h>                            
int main(void)
{

int EUR,GBP,JPY,CAD,RUR,US;  
float fCAD,fEUR,fGBP,fJPY,fRUR,fUS;
char option;
  EUR=1;
  GBP=2;
  JPY=3;
  CAD=4;
  RUR=5;

   
  fEUR=0.829643f;              
  fGBP=0.548242f;
  fJPY=110.631f;
  fCAD=1.31751f;
  fRUR=29.1800f;                                                                                  
   fUS=1.00f;
  printf("Select a currency type\n\n");
  printf("1=European Euro 2=United Kingdom Pound 3=Japanese Yens 4=Canadian Dollars 5=Russian Rubles\n");
  printf("Select the 4=Canadian Dollars currency type\n");
  printf("Enter 0 to exit\n\n");

while(1){

printf("Enter your choice:");

option=getch();
switch(option)
{
case '1':
printf("The selected currency type is the European Euro of %f equivalent to %f US  Dollar\n",fEUR,fUS);
break;
case '2':
printf("The selected currency type is the United Kingdom Pound of %f equivalent to %f US  Dollar\n",fGBP,fUS);
break;
case'3':
printf("The selected currency type is the Japanese Yens of %f equivalent to %f US  Dollar\n",fJPY,fUS);
break;
case'4':
printf("The selected currency type is the Canadian Dollars of %f equivalent to %f US  Dollar\n",fCAD,fUS);
break;
case '5':
printf("The selected currency type is the Russian Rubles of %f equivalent to %f US  Dollar\n",fRUR,fUS);
break;
case '0':
printf("exiting...\n");
return (0);
break;
default:
scanf("%c", &option);
option=getch();

}
}
getch();
return 0;                          
}
Question History
0
Industry Leaders: 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!

 

Author Comment

by:RebeccaFusco
ID: 11834590
Oh! I should have known that. Thanks New question :-) I am trying to get this to print out all dollar signs in a row of  6 and a column of 10. I am missing something? I think that it is line 10? Thanks  

 #include <stdio.h>
#define Rows 6
#define CHARS 10
int main (void)
{
int row;
char ch;
for(row=0;row<Rows;row++)
{
for(ch = '&';ch)
printf("%c",ch);
printf("\n");
}
getch();
return 0;                          
}          
0
 

Author Comment

by:RebeccaFusco
ID: 11834739
I got a little further as to a few mistakes but am still having a problem :-( Thanks

#include <stdio.h>
#define Rows 6
#define CHARS 10
int main (void)
{
int row;
char ch;
for(row=0;row<Rows;row++)
{
for(ch = '$';lt('$'+CHARS);ch++)
printf("%c",ch);
printf("\n");
}
getch();
return 0;                          
}          
0
 
LVL 86

Expert Comment

by:jkr
ID: 11834740
That should be more like

 #include <stdio.h>
#define Rows 6
#define CHARS 10
int main (void)
{
int row;
int ch;
for(row=0;row<Rows;row++)
{
for(ch = 0;ch < CHARS;ch++)
printf("$");
printf("\n");
}
getch();
return 0;                          
}          
0
 

Author Comment

by:RebeccaFusco
ID: 11834789
So my mistake was in the inner loop. To just print a continous item ch can  be set at 0 and CHARS is set to print out under 10 rows? Thanks

(ch = 0;ch < CHARS;ch++)
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 11834809
Yes, that's basically the way to go.
0
 

Author Comment

by:RebeccaFusco
ID: 11834832
Thank you as usual you are wonderful  :-)
0

Featured Post

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!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

762 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