want to quit program at any prompt with q

I have only been learning c++ for the last 3 weeks. Here is my code for a calculator, it works ok, but I was wondering if my code is any good. Also, I can quit with q at a character prompt, but I don't know how to quit with q at an integer prompt. Any suggestions for me would be greatly appreciated. One more thing is it alright to use continue the way I have?
Thanks,
D.B



#include <iostream>
#include <cmath>
#include<string>
using namespace std;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
int main()


    // declaring variables:
{ 
  double value1,value2;
  char operation; 
  int x=0; 
  cout<<endl;
  cout<<"\t\t"<<"   "<<"Welcome to my calculator : "<<endl;    
  
                                                        
    // enter value to compute
    
    do {
    cout<<"    "<<"________________________________________________________________________\n\n";   
        
  cout<<"Enter a value you want to work with : ";
  cin >>value1;cout<<endl;


    // enter operation want performed  
                           
  cout<<"Enter the operation you want to perform (enter q or Q to exit program) "<<endl<<endl;
  cout<<"Choose from these options  +  -  *  /  ^  %  ! ";
  cin >> operation; cout<<endl;
  

    // entering q or Q to exit program      
             
  if (operation == 'q' || operation == 'Q')
   {cout<<"\t\t\t\t\tGoodbye for now! "<<endl<<endl;
   system("PAUSE");
   return EXIT_SUCCESS;
   } 
   
  // computation ^ square
                      
  if (operation == '^')
   {
   cout<<"\t\tThe square of "<<value1<<" = "<<value1 * value1<<endl<<endl;
   continue;
   } 
   
                  
  // computation factorial ! convert value1 to an integer in order to calculate             
  // 
  { 
                 
  int n =int(value1);
  if(value1 > 12) {cout <<"\tNo factorial of any number greater than 1, try again 2 "<<endl<<endl;continue;}
  if (n <0 ) {cout <<"\tNo factorial of a negative number, try again "<<endl<<endl;continue;}
   int f = 1;
   while (n >1)
   f*=n--;
    if (operation == '!') 
     {
     cout<<"\t\tThe factorial of "<<value1<<" = " <<f<<endl<<endl;
     continue;
     }           
  }   
    //enter another value if needed  
                
  cout<<"Enter second value you want to work with : ";
  
  cin >>value2;cout<<endl;
  
  
  // computation remainder %  convert value1 and value2 to integers in order to calculate  
  {
  int n = int(value1);
  int m = int(value2);
               
   if (operation == '%') cout<<"\t\tThe remainder of "<<value1<<" / "<<value2<< " = "<< n % m<<endl<<endl;
  }  

    
    // computations + - * /   
    
   if (operation == '+') cout<<"\t\t"<<value1<<" + "<<value2<<" = "<< value1 + value2<<endl<<endl;
   else if (operation == '-') cout<<"\t\t"<<value1<<" - "<<value2<<" = "<< value1 - value2<<endl<<endl;
   else if (operation == '*') cout<<"\t\t"<<value1<<" x "<<value2<<" = "<<value1 * value2<<endl<<endl;            
   else if (operation == '/') cout<<"\t\t"<<value1<<" / "<<value2<<" = "<< value1 / value2<<endl<<endl;
             
  
		  x++;
		} while (x < 100);
		
	 
  /* Exit program (pause so the program output window
     doesn't close until you press a key */
      
  system("PAUSE");
  return EXIT_SUCCESS;
}
Last edited on
Topic archived. No new replies allowed.