Guest User

While Loop

a guest
Sep 15th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <ctype.h>
  4. #include <string>
  5. #include <array>
  6. using namespace std;
  7. int Addition(int x,int y);
  8. int Subtraction(int x,int y);
  9. int Multiplication(int x,int y);
  10. int Division(int x,int y);
  11.  
  12. void main(){
  13.     int x = 0;
  14.     while( x == 0 ){
  15.     int num1;
  16.     string oper;
  17.     int num2;
  18.    
  19.     cout << "******************************************" << endl;
  20.     cout << "*       Welcome to C++ Calculator        *" << endl;
  21.     cout << "*                   By                   *" << endl;
  22.     cout << "*                ryan7136                *" << endl;
  23.     cout << "******************************************" << endl;
  24.     cout << "*       Please enter an operation:       *" << endl;
  25.     cout << "*            Your choices are:           *" << endl;
  26.     cout << "*  add, subtract, multiply, divide, pi,  *" << endl;
  27.     cout << "*                 and exit               *" << endl;
  28.     cout << "******************************************" << endl;
  29.  
  30.     getline(cin , oper);
  31.     cin.clear();
  32.  
  33.     if(oper == "add"){
  34.     cout << "Enter the first number:";
  35.     cin >> num1;
  36.     cout << "Enter the second number:";
  37.     cin >> num2;
  38.     cout << "The sum is: " << Addition(num1,num2) << "." << endl;
  39.     }
  40.     if(oper == "subtract"){
  41.     cout << "Enter the first number:";
  42.     cin >> num1;
  43.     cout << "Enter the second number:";
  44.     cin >> num2;
  45.     cout << "The sum is: " << Subtraction(num1,num2) << "." << endl;
  46.     }
  47.     if(oper == "multiply"){
  48.     cout << "Enter the first number:";
  49.     cin >> num1;
  50.     cout << "Enter the second number:";
  51.     cin >> num2;
  52.     cout << "The sum is: " << Multiplication(num1,num2) << "." << endl;
  53.     }
  54.     if(oper == "divide"){
  55.     cout << "Enter the first number:";
  56.     cin >> num1;
  57.     cout << "Enter the second number:";
  58.     cin >> num2;
  59.     cout << "The sum is: " << Division(num1,num2) << "." << endl;
  60.     }
  61.     if(oper == "pi"){
  62.     cout << "pi: 3.14159265358979323846264338327950288" << endl;
  63.     }
  64.     if(oper == "exit"){
  65.     int x = 12;
  66.     }
  67.     system("CLS");
  68.     }
  69. }
  70.  
  71.  
  72. int Addition(int x, int y){
  73.     int answer;
  74.     answer = x + y;
  75.     return answer;
  76. }
  77. int Subtraction(int x, int y){
  78.     int answer;
  79.     answer = x - y;
  80.     return answer;
  81. }
  82. int Multiplication(int x, int y){
  83.     int answer;
  84.     answer = x * y;
  85.     return answer;
  86. }
  87. int Division(int x, int y){
  88.     int answer;
  89.     answer = x / y;
  90.     return answer;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment