Solved

Chose exit option to quit the program

Posted on 2004-08-18
9
326 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
posix semaphore deadlock 13 123
Problem with MFCApp 78 380
libcurl - taking long time on curl_easy_perform 11 399
C hashtable library 3 90
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…
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 opening and writing to files 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.

785 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