Created
June 14, 2018 22:56
-
-
Save jcarter62/fbd188f1b9c4a664b9f77ecf461c6ea4 to your computer and use it in GitHub Desktop.
simple c++ calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // main.cpp | |
| // calculator | |
| // | |
| // Created by Jim Carter on 6/14/18. | |
| // | |
| #include <iostream> | |
| using namespace std; | |
| int main(int argc, const char * argv[]) { | |
| // insert code here... | |
| std::cout << "Hello, World!\n"; | |
| int a; | |
| int b; | |
| char op; | |
| int opOk; | |
| int result; | |
| int done; | |
| done = 0; | |
| while ( done <= 0 ) { | |
| char again; | |
| cout << "Please provide two numbers, and an operator (+-*/)\n"; | |
| cin >> a; | |
| cin >> b; | |
| cin >> op; | |
| opOk = 0; | |
| if ( ( op == '+' ) || ( op == '-' ) || ( op == '*' ) || ( op == '/' ) ) { | |
| opOk = 1; | |
| } | |
| if ( ! opOk ) { | |
| cout << "Invalid Operator, please use one of (+-*/) \n"; | |
| } else { | |
| result = 0; | |
| if ( op == '+' ) { | |
| result = a + b; | |
| } | |
| if ( op == '-' ) { | |
| result = a - b; | |
| } | |
| if ( op == '*' ) { | |
| result = a * b; | |
| } | |
| if ( op == '/' ) { | |
| result = a / b; | |
| } | |
| cout << a << op << b << " = " << result << "\n"; | |
| bool ynQ = false; | |
| while ( ! ynQ ) { | |
| cout << "Again ? (Y/N) \n"; | |
| cin >> again; | |
| if (( again == 'Y' ) || ( again == 'y' )) { | |
| done = 0; | |
| ynQ = true; | |
| } | |
| if ( ( again == 'N' ) || ( again == 'n' ) ) { | |
| ynQ = true; | |
| done = 1; | |
| } | |
| } | |
| } | |
| } | |
| cout << "..... see you later .....\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment