### Exercises for Beginners 2

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:

1.Using if statements:
 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include using namespace 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"<>choice; if(choice==1) {cout<<"Addition of the numbers is:"<

2. Using switch-case:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243`` `````` #include using namespace 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"<>choice; switch(choice) case 1: cout<<"Addition of the numbers is:"<

3. Using using functions for each operation:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980`` `````` #include using namespace 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; cout<<"Input the second number.\n"; cin>>y; cout<<"\n**Subtraction of numbers:"<>x; cout<<"Input the second number.\n"; cin>>y; cout<<"\n**Multiplaction of the numbers:"<>x; cout<<"Input the second number.\n"; cin>>y; cout<<"\n**Division of the numbers:"<
Topic archived. No new replies allowed.