Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Chose exit option to quit the program

Posted on 2004-08-18
9
Medium Priority
?
356 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
Independent Software Vendors: 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

927 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