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
|
#include <iostream>
using namespace std;
void SumNum (float &a, float &b);
void SubNum (float &a, float &b);
void MulNum (float &a, float &b);
void DivNum (float &a, float &b);
void ModNum (float &a, float &b);
int main()
{
int choice;
int agian = 1;
float *num1 = new float;
float *num2 = new float;
when( agian == 1){
cout << "Welcome to my simple calculator!" << endl;
cout << "********************************" << endl;
cout << "1) Addition (x+y)" << endl;
cout << "2) Subtraction (x-y)" << endl;
cout << "3) Multiplication (x*y)" << endl;
cout << "4) Division (x/y)" << endl;
cout << "5) Modulation (x%y)" << endl;
cout << "6) Exit the Calculator" << endl;
cout << "*********************************" << endl;
cout << "Please Enter the number of the operator you would like to compute:";
cin >> choice;
cout << "Enter the first number of the equation(x) :";
cin >> *num1;
cout << "Enter the second number of the equation(y) :";
cin >> *num2;
switch (choice){
case'1':
SumNum(*num1,*num2);
break;
case'2':
SubNum(*num1,*num2);
break;
case'3':
MulNum(*num1,*num2);
break;
case'4':
DivNum(*num1,*num2);
break;
case'5':
ModNum(*num1,*num2);
break;
case'6':
agian = 0;
break;
}
}
if ( agian == 0){
cout << "Bye!" << endl;
}
return 0;
}
void SumNum(float &a, float &b){
cout << "your equation is:" << a << " + " << b << " = ??"<<endl;
cout << "your answer is:"<< a+b << endl;
}
void SubNum(float &a, float &b){
cout << "your equation is:" << a << " - " << b << " = ??"<<endl;
cout << "your answer is:"<< a-b << endl;
}
void MulNum(float &a, float &b){
cout << "your equation is:" << a << " * " << b << " = ??"<<endl;
cout << "your answer is:"<< a*b << endl;
}
void DivNum(float &a, float &b){
if(b==0){
cout << "invalid. cannont divide by 0";
}
else cout << "your equation is:" << a << " / " << b << " = ??"<<endl;
cout << "your answer is:"<< a/b << endl;
}
void ModNum(float &a, float &b){
cout << "your equation is:" << a << " % " << b << " = ??"<<endl;
cout << "your answer is:"<< a/b << endl;
}
| |