1234567891011121314151617181920212223242526272829303132333435363738
#include <iostream> #include <cmath> #include <cstdlib> #include <iomanip> using namespace std; int main(int argc, char *argv[]) { double numOne, numTwo, answer; char sign; cout<<"Enter your equation (ex: 1 + 2)"<<endl; cin>>numOne>>sign>>numTwo; //Addition if(sign == '+'){ cout<<numOne<<" + "<<numTwo<<" = "<<numOne+numTwo; } //Subtraction else if(sign == '-'){ cout<<numOne<<" - "<<numTwo<<" = "<<numOne-numTwo; } //Multiplication else if(sign == '*'){ cout<<numOne<<" * "<<numTwo<<" = "<<numOne*numTwo; } //Division with 0 Error else if(sign == '/' && numTwo == 0){ cout<<"Invalid operation, you can not divide by 0"; } //Division if(sign =='/' && numTwo != 0){ cout<<numOne<<" / "<<numTwo<<" = "<<numOne/numTwo; } return 0; }
1234567891011121314151617181920212223242526272829303132333435363738394041424344
#include <iostream> #include <cmath> #include <cstdlib> #include <iomanip> using namespace std; int main(int argc, char *argv[]) { bool loop=1; double numOne, numTwo, answer; char sign, Restart; do{ cout<<"Enter your equation (ex: 1 + 2)"<<endl; cin>>numOne>>sign>>numTwo; //Addition if(sign == '+'){ cout<<numOne<<" + "<<numTwo<<" = "<<numOne+numTwo; } //Subtraction else if(sign == '-'){ cout<<numOne<<" - "<<numTwo<<" = "<<numOne-numTwo; } //Multiplication else if(sign == '*'){ cout<<numOne<<" * "<<numTwo<<" = "<<numOne*numTwo; } //Division with 0 Error else if(sign == '/' && numTwo == 0){ cout<<"Invalid operation, you can not divide by 0"; } //Division if(sign =='/' && numTwo != 0){ cout<<numOne<<" / "<<numTwo<<" = "<<numOne/numTwo; } cout<<endl<<"Would you like to Restart? Y or N?"<<endl; cin>>Restart; cout<<endl; if(Restart=='n'||Restart=='N') loop=0; }while(loop); return 0; }