Simple Calculator in C++ - Wisdom Lighter

Tuesday, 22 May 2018

Simple Calculator in C++

C++

Program:

#include <iostream>

using namespace std;

int main()
{
     float a,b;
char operation;
cout<<"\n Enter 1st number =";
cin>>a;
cout<<" Enter 2nd number =";
cin>>b;
cout<<" Enter\n 'a' for addition\n 's' for subtraction\n 'm' for multiplication\n 'd' for division , "<<endl;
cin>>operation;
cout<<"Answer is =";

switch(operation){

case 'a':
    cout << a+b;
break;
case 's':
    cout << a-b;
break;
case 'm':
cout<<a*b;
break;
case 'd':
     cout << a/b;
break;


}

getch();
}


Output:


Add in C++

Subtract in C++

Multiply in C++

Divide in C++



No comments:
Write comments