Solved

Chose exit option to quit the program

Posted on 2004-08-18
9
308 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
Comment Utility
You already have one:

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

Author Comment

by:RebeccaFusco
Comment Utility
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
Comment Utility
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
 

Author Comment

by:RebeccaFusco
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:RebeccaFusco
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, that's basically the way to go.
0
 

Author Comment

by:RebeccaFusco
Comment Utility
Thank you as usual you are wonderful  :-)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 and use pointers in the C programming language.
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.

771 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

11 Experts available now in Live!

Get 1:1 Help Now