Code:
#include<iostream>
int main()
{
using namespace std;
cout<<"\nEnter first num:";
double a,b;
cin>>a;
cout<<"\nEnter second number:";
cin>>b;
char ch;
cout<<"\nChoose one:\n+,-,*,/";
cin>>ch;
if(ch=='+')
{
cout<<endl<<a+b;
cin.get();
}
if(ch=='-')
{
cout<<endl<<a-b;
cin.get();
}
if(ch='*')
{
cout<<endl<<a*b;
cin.get();
}
if(ch='/')
{
cout<<endl<<(a/b);
cin.get();
}
cin.get();
return 0;
}
Here are few outputs i got:
First:
Code:
Enter First num:8
Enter second number:6
choose one:
+,-,*,/
+
14
48
1.33333
second:
Code:
Enter First num:78
Enter second number:5
choose one:
+,-,*,/
-
73
390
15.6
Third:
Code:
Enter First num:54
Enter second number:25
choose one:
+,-,*,/
*
1350
2.16
Fourth:
Code:
Enter First num:7
Enter second number:3
choose one:
+,-,*,/
/
21
2.33333
I included cin.get() in all the four if blocks bcoz the window was shutting down automatically.
I am using Dev c++
Thanks!!