online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
//simple calculator #include <iostream> #include <iomanip> using namespace std; void print(string text) { cout<<text; //display the value of text } void displayOptions() { cout<<"\n\t-------------------"; cout<<"\n\tOPERATION OPTIONS"; cout<<"\n\t-------------------"; cout<<"\n\t1-Multiplication"; cout<<"\n\t2-Division"; cout<<"\n\t3-Addition"; cout<<"\n\t4-Subtration"; } int readNumberOnly(string text) { /// "12345" is not the same as 12345 (mind the double quotations) /// ^^^^^ is a string ^^^^^ is just a number/numbers ///string automatically adds double quotation on a variable /// stoi removes the double quotation /// stoi means string to integer bool valid=false; string input; int x; while(valid==false) { print(text); cin>>input; try { x=stoi(input); ///is used to convert string to number "12345" --> 12345 if (x>0) { valid=true; } else { cout<<"\tInput must be greater than 0\n"; } } catch(...) { print("\n\tInvalid Input!!!"); print("\n\tPlease Input Number Only"); } } return x; } int errorHandling() { bool valid=false; int operation=0; valid=false; while(valid==false) { cout<<"\n\tEnter choice:"; cin>>operation; if (operation>=1 && operation<=4) valid=true; else cout<<"\tInput range is from 1 to 4 only.\n"; } } int main() { int num1=0,num2=0; int operation=0; float result=0.0; bool valid=false; print("\tJules Mayono CPE11S1"); num1=readNumberOnly("\n\tEnter 1st Number: "); num2=readNumberOnly("\n\tEnter 2nd Number: "); displayOptions(); errorHandling(); switch(operation) { case 1:cout<<"\n\tOPERATION:MULTIPLICATION"; result=num1*num2; cout<<"\n\t"<<num1<<" * "<<num2<<" = "<<result; break; case 2:cout<<"\n\tOPERATION:DIVISION"; result=(float)num1/num2; cout<<"\n\t"<<num1<<" / "<<num2<<" = "<<fixed<<setprecision(2)<<result; break; case 3:cout<<"\n\tOPERATION:ADDITION"; result=num1+num2; cout<<"\n\t"<<num1<<" + "<<num2<<" = "<<result; break; case 4:cout<<"\n\tOPERATION:SUBTRACTION"; result=num1-num2; cout<<"\n\t"<<num1<<" - "<<num2<<" = "<<result; break; }//switch(x) }//int main()
//simple calculator #include <iostream> #include <iomanip> using namespace std; void print( string text) // void type does not return a value { cout<<text; //display the value of text } void displayOptions() { cout<<"\n\t-------------------"; print("\n\tOPERATION OPTIONS"); cout<<"\n\t-------------------"; cout<<"\n\t1-Multiplication"; cout<<"\n\t2-Division"; cout<<"\n\t3-Addition"; print("\n\t4-Subtraction"); } int readNumberOnly(string text) { /// "12345" is not the same as 12345 // stoi() bool valid=false; string input; int x; while(valid==false) { print(text); cin>>input; try { x=stoi(input); // stoi() - converts string to integer: "12345"-->12345 // stof() is used to convert string to float: "12.45"-->12.45 if (x>0) { valid=true; } else { cout<<"\tInput must be greater than 0\n"; } }// catch(...) { print("\n\tInvalid Input!!!"); print("\n\tPlease Input Number Only...\n"); } }// end of while(valid==false) return x; } //end of readNumberOnly(string text) int errorHandling() { bool valid=false; int operation; string x; while(valid==false) { cout<<"\n\tEnter choice:"; cin>>operation; try { operation=stoi(x); if (operation>=1 && operation<=4) { valid=true; } else { cout<<"\tInput range is from 1 to 4 only.\n"; } } catch(...) { print("\n\tInvalid Input!!!"); print("\n\tPlease Input Number Only...\n"); } } return operation; } int main() { int num1=0,num2=0; int operation=0; float result=0.0; bool valid=false; num1=readNumberOnly("\tEnter 1st Number:"); num2=readNumberOnly("\tEnter 2nd Number:"); displayOptions(); errorHandling(); switch(operation) { case 1:cout<<"\n\tOPERATION:MULTIPLICATION"; result=num1*num2; cout<<"\n\t"<<num1<<" * "<<num2<<" = "<<result; break; case 2:cout<<"\n\tOPERATION:DIVISION"; result=(float)num1/num2; cout<<"\n\t"<<num1<<" / "<<num2<<" = "<<fixed<<setprecision(2)<<result; break; case 3:cout<<"\n\tOPERATION:ADDITION"; result=num1+num2; cout<<"\n\t"<<num1<<" + "<<num2<<" = "<<result; break; case 4:cout<<"\n\tOPERATION:SUBTRACTION"; result=num1-num2; cout<<"\n\t"<<num1<<" - "<<num2<<" = "<<result; break; }//switch(x) return 0; }//int main()

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue