I made a calculator in C++. I wanted to ask is this code well written, understandable, and alright.
#include <iostream>
using namespace std;
int main() {
// Declares the variable to store the asked value
int num1, num2;
char op;
// Asks the user for the input of numbers and the operation
cin >> num1;
cin >> op;
cin >> num2;
// Declares a variable for the answer
int result;
// Handles all the conditions of the operation
if(op == '+') {
result = num1 + num2;
} else if(op == '-'){
result = num1 - num2;
} else if(op == '*') {
result = num1 * num2;
} else if(op == '/') {
result = num1 / num2;
} else {
cout << "Invalid values";
cout<<endl<<endl;
}
// Outputs the result
cout << "Answer: ";
cout << result;
// Ouputs a thankyou message
cout<<endl<<endl;
cout << "THANKS FOR USING THIS";
return 0;
}
using namespace std;
. See this SO question for more info. \$\endgroup\$