Write a small calculator that takes as input one of the four arithmetic operations, the two arguments to those operations, and then prints out the result;
there is more then one solutions for that exercises:
#include <iostream>
usingnamespace std;
int main()
{
int first, second, choice; // integers for stroring the numbers and selected operation
cout<<"Input the first number.\n";
cin>>first;
cout<<"Input the second number.\n";
cin>>second;
cout<<"--Choose your operation--\n"<<endl;
cout<<"1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n";
cin>>choice;
if(choice==1)
{cout<<"Addition of the numbers is:"<<first+second<<endl; }
elseif(choice==2)
{cout<<"Subtraction of the numbers is:"<<first-second<<endl; }
elseif(choice==3)
{cout<<"Multiplication of the numbers is:"<<first*second<<endl; }
elseif(choice==4)
{cout<<"Division of the numbers is:"<<first/second<<endl; }
system("pause");
}
#include <iostream>
usingnamespace std;
int main()
{
int first, second, choice; // integers for stroring the numbers and selected operation
cout<<"Input the first number.\n";
cin>>first;
cout<<"Input the second number.\n";
cin>>second;
cout<<"--Choose your operation--\n"<<endl;
cout<<"1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n";
cin>>choice;
switch(choice)
case 1:
cout<<"Addition of the numbers is:"<<first+second<<endl;
break;
case 2:
cout<<"Subtraction of the numbers is:"<<first-second<<endl;
break;
case 3:
cout<<"Multiplication of the numbers is:"<<first*second<<endl;
break;
case 4:
cout<<"Division of the numbers is:"<<first/second<<endl;
break;
system("pause");
}
#include <iostream>
usingnamespace std;
int menu()
{
int a;
while(1)
{
cout<<"**********************\n";
cout<<"**Choose your operation**\n";
cout<<"**********************\n";
cout<<"1.Addition\n2.Subtraction\n3.Multiplaction\n4.Division\n5.Exit\n";
cin>>a;
if(a==1||a==2||a==3||a==4||a==5){break;}
cout<<"Bad ınput.\n";}
return a;
}
void addition(int x, int y)
{
cout<<"Input the first number.\n";
cin>>x;
cout<<"Input the second number.\n";
cin>>y;
cout<<"\n**Addition of numbers:"<<x+y<<endl;
}
void subtraction(int x, int y)
{
cout<<"Input the first number.\n";
cin>>x;
cout<<"Input the second number.\n";
cin>>y;
cout<<"\n**Subtraction of numbers:"<<x-y<<endl;
}
void multiplaction(int x, int y)
{
cout<<"Input the first number.\n";
cin>>x;
cout<<"Input the second number.\n";
cin>>y;
cout<<"\n**Multiplaction of the numbers:"<<x*y<<endl;
}
void division(double x, double y){
cout<<"Input the first number.\n";
cin>>x;
cout<<"Input the second number.\n";
cin>>y;
cout<<"\n**Division of the numbers:"<<x/y<<endl;
}
int main()
{
int x,y,b;
b=menu();
if(1==b){addition(x,y);}
if(2==b){subtraction(x,y);}
if(3==b){multiplaction(x,y);}
if(4==b){division(x,y);}
if(5==b) {return 0;}
}