Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int main()
- {
- start:
- int a, b, c;
- int op, select(0);
- while (select != -1)
- {
- cout<<"----------------------\n";
- cout<<"Number"<<setw(14)<<"Operation";
- cout<<"\n----------------------\n";
- cout<<"1"<<setw(20)<<"Addition\n"<<"2"<<setw(20)<<"Subtraction\n"<<"3"<<setw(20)<<"Multiplication\n"<<"4"<<setw(20)<<"Division\n"<<"5"<<setw(20)<<"Modulus\n"<<"6"<<setw(20)<<"Difference\n"<<"7"<<setw(20)<<"Exit Program\n";
- cout<<"Enter operation number: ";
- cin>>op;
- while ((op>7) || (op<1))
- {
- cout<<"Operation must be a number from 1 - 7\n";
- cout<<"Enter operation number: ";
- cin>>op;
- }
- if (op == 7)
- return 0;
- cout<<"Enter the first number: ";
- cin>>a;
- cout<<"\nEnter the second number: ";
- cin>>b;
- switch(op)
- {
- case 1: c = a+b;
- break;
- case 2: while ((select<1)||(select>2))
- {
- cout<<"Press 1 for "<<a<< " - "<<b<<endl<<"Press 2 for "<<b<<" - "<<a<<endl;
- cin>>select;
- switch(select)
- {
- case 1: c = a-b;
- break;
- case 2: c = b-a;
- break;
- default: cout<<"Number must be 1 or 2\n";
- }
- }
- break;
- case 3: c = a*b;
- break;
- case 4: while ((select<1)||(select>2))
- {
- cout<<"Press 1 for "<<a<< " / "<<b<<endl<<"Press 2 for "<<b<<" / "<<a<<endl;
- cin>>select;
- switch(select)
- {
- case 1: c = a/b;
- break;
- case 2: c = b/a;
- break;
- default: cout<<"Number must be 1 or 2\n";
- }
- }
- break;
- case 5: while ((select<1)||(select>2))
- {
- cout<<"Press 1 for "<<a<< " % "<<b<<endl<<"Press 2 for "<<b<<" % "<<a<<endl;
- cin>>select;
- switch(select)
- {
- case 1: c = a%b;
- break;
- case 2: c = b%a;
- break;
- default: cout<<"Number must be 1 or 2\n";
- }
- }
- break;
- case 6: c = abs(a-b);
- break;
- case 7: return 0;
- default: cout<<"Must be a number from 1 to 7";
- }
- cout<<"The answer is: "<<c<<endl;
- }
- system("pause");
- }
Add Comment
Please, Sign In to add comment