Dec 8, 2013 at 7:59pm UTC
Hello everyone,
i have a project to develop a simple calculator which loops.i did it.but is there another way of making it? a better way perhaps? can i use return function? if yes,how? how can i improve this code in general.
please help me because its due in 2 days.:(
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
double num1,num2;
char operation;
string redo;
do
{
cout<<" Please enter an operation (+,-,*,/):";
cin>>operation ;
cout<<endl<<endl;
cout<<"Please enter two numbers to calculate:";
cout<<"\n\n";
cout<<"First Number:";
cin>>num1;
cout<<"Second Number:" ;
cin>>num2;
cout<<endl;
switch (operation)
{
case'+':
cout<<"The sum of numbers "<<num1<<" and "<<num2<<" = ";
cout<<num1+num2<<endl;
break;
case'-':
cout<<"The substraction of numbers "<<num1<<" and "<<num2<<" = ";
cout<<num1-num2<<endl;
break;
case'*':
cout<<"The multiplication of numbers "<<num1<<" and "<<num2<<" = ";
cout<<num1*num2<<endl;
break;
case'/':
cout<<"The division of two numbers "<<num1<<" and "<<num2<<" = ";
if(num2==0)
{
cout<<"not valid"<<endl;
}
cout<<(num1/num2)<<endl;
break;
default:
cout<<"invalid"<<endl;
}
cout<<endl<<endl;
cout<<"Enter yes to continue calculating or no to end the calculator: ";
cin>>redo;
cout<<endl<<endl;
}
while(redo!="no");
return 0;
}
Last edited on Dec 8, 2013 at 7:59pm UTC