Solved

Chose exit option to quit the program

Posted on 2004-08-18
9
334 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
  • 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

861 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