![](http://www.weebly.com/weebly/images/file_icons/exe.png)
Simple Calculator | |
File Size: | 470 kb |
File Type: | exe |
C++ Code for Simple Calculator
#include <iostream>
#include <cmath>
using namespace std;
int main()
{ float x, y;
char op;
// first digit
cout<<"enter first digit"<<endl;
cin>> x;
cout<< "you entered \t"<< x <<endl;
cout<< endl;
// second digit
cout<< "please enter second digit" <<endl;
cin>>y;
cout<< "you entered \t" << y <<endl;
cout<<endl;
//operator
cout<<"please enter an operator (+ , - , * , / )"<< endl;
cin >> op;
cout <<endl;
// if statements
if (op == '+') //addition
{
cout<< "answer is \t" << x+y<<endl;
}
if (op == '-') //subtraction
{
cout <<" the answer is \t" << x-y<< endl;
}
if (op =='*') //multiplication
{
cout<<" the answer is \t" << x*y<<endl;
}
if (op == '/') // division
{
cout << " the answer is \t"<< x/y<<endl;
}
//stall for exit
char exit;
cout<<"\n press close in titlebar to exit"<< endl;
cin>> exit ;
return 0;
}