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 97 98 99 100 101 102
|
#include <iostream>
#include <cstdlib>
#include<math.h>
using namespace std;
int addition()
{long int a, b;
cout<<"Ok then! You have chosen wisely..ADDITION!"<<endl;
cout<<"Now please enter your first number:";
cin>>a;
cout<<endl;
cout<<"Excellent choice! What about the second? It is:";
cin>>b;
cout<<endl;
a=a+b;
cout<<"Hm.. Let me think! Your result sholud be.."<<a<<"!"<<endl;
return 0;}
int substraction()
{long int a, b;
cout<<"Ok then! You have chosen wisely..SUBSTRACTION!"<<endl;
cout<<"Now please enter your first number:";
cin>>a;
cout<<endl;
cout<<"Excellent choice! What about the second? It is:";
cin>>b;
cout<<endl;
a=a-b;
cout<<"Hm.. Let me think! Your result sholud be.."<<a<<"!"<<endl;
return 0;}
int multiplication()
{long int a, b;
cout<<"Ok then! You have chosen wisely..MULTIPLICATION!"<<endl;
cout<<"Now please enter your first number:";
cin>>a;
cout<<endl;
cout<<"Excellent choice! What about the second? It is:";
cin>>b;
cout<<endl;
a=a*b;
cout<<"Hm.. Let me think! Your result sholud be.."<<a<<"!"<<endl;
return 0;}
int division()
{float a, b;
long double c;
cout<<"Ok then! You have chosen wisely..DIVISION!"<<endl;
cout<<"Now please enter your first number:";
cin>>a;
cout<<endl;
cout<<"Excellent choice! What about the second? It is:";
cin>>b;
cout<<endl;
c=a/b;
cout<<"Hm.. Let me think! Your result sholud be.."<<c<<"!"<<endl;
return 0;}
int power()
{long int a, b, result=1;
cout<<"Ok then! You have chosen wisely..POWER!"<<endl;
cout<<"Now please enter your base:";
cin>>a;
cout<<endl;
cout<<"Excellent choice! What about the power? It is:";
cin>>b;
cout<<endl;
for(; b>0; b--){result=result*a;};
cout<<"Hm.. Let me think! Your result sholud be.."<<result<<"!"<<endl;
return 0;}
int square()
{long double a, b;
cout<<"Ok then! You have chosen wisely..SQUARE ROOT!"<<endl;
cout<<"Now please enter your number:";
cin>>a;
cout<<endl;
b=sqrt(a);
cout<<"Hm.. Let me think! Your result sholud be.."<<b<<"!"<<endl;
return 0;}
int main()
{cout<<"Hello friend! This program is to calculate some mathematycal operations for you."<<endl;
label1:
cout<<"Please enter the operation you want to execute as +(for addition), -(for substraction), *(for multiplication), /(for division), ^(for power), r(for square root)"<<endl;
enum answer_type {add='+', sub='-', mul='*', div='/', pow='^', sqrt='r', invalid='0'} answer;
char input, choice;
cin>>input;
switch(input)
{case add: addition();answer= answer_type(input);break;
case sub: substraction();answer= answer_type(input);break;
case mul: multiplication();answer= answer_type(input);break;
case div: division();answer= answer_type(input);break;
case pow: power();answer= answer_type(input);break;
case sqrt: square();answer= answer_type(input);break;
default: cout<<"Incorrect answer!"<<endl;answer=invalid;break;};
system("PAUSE");
cout<<"Now if you want to make more operations with my program press c, if not press q."<<endl;
label3:
cout<<"Your choice will be:";
cin>>choice;
cout<<endl;
switch(choice)
{case 'c': goto label1; break;
case 'q': goto label2; break;
default: goto label3; break;};
label2:
return 0;
}
|