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 103
|
#include <iostream>
using namespace std;
long int addition (long int a, long int b)
{
long int c;
c=a+b;
return (c);
}
long int subtraction (long int a, long int b)
{
long int c;
c=a-b;
return (c);
}
long int multiplication (long int a, long int b)
{
long int c;
c=a*b;
return (c);
}
long int division (long int a, long int b)
{
long int c;
c=a/b;
return (c);
}
void printmessage ()
{
cout << "\n" << "INVALID RESPONSE!" << "\n" << "\n";
}
int main ()
{
long int a, b, c;
char change;
char done;
cout << "Welcome to V.2 of the calculator." << "\n";
cout << "Please enter your first number: ";
cin >> a;
do{
cout << "Please enter your next number: ";
cin >> b;
do{
cout << "Would you like to add [A], subtract [S], divide [D], or multliply [M]" << ": ";
cin >> change;
if (change=='A')
{
c = addition (a,b);
cout << a << " + " << b << " = " << c;
}
else if (change=='S')
{
c = subtraction (a,b);
cout << a << " - " << b << " = " << c;
}
else if (change=='D')
{
c = division (a,b);
cout << a << " / " << b << " = " << c;
}
else if (change=='M')
{
c = multiplication (a,b);
cout << a << " * " << b << " = " << c;
}
else
{
printmessage();
}
}while ((change!='A') && (change!='S') && (change!='M') && (change!='D'));
cout << "\n";
cout << "Are you done with: " << c;
cout << "\n";
do{
cout << "Yes [Y], No [N]: ";
cin >> done;
while ((done!='N') && (done!='Y'))
{
printmessage();
break;
}
}while ((done!='Y') && (done!='N'));
a=c;
} while (done!='Y');
return 0;
}
|