diff --git a/SimpleCalculator/README.md b/SimpleCalculator/README.md new file mode 100644 index 0000000..4f07bd9 --- /dev/null +++ b/SimpleCalculator/README.md @@ -0,0 +1,13 @@ +# Simple Calculator (C++) + +This is a basic calculator program written in C++. +It takes two integers and an operator (`+`, `-`, `*`, `/`) as input and displays the result. + +--- + +## 🔹 How to Compile and Run + +1. Open terminal in the `SimpleCalculator` folder. +2. Compile the program: + ```bash + g++ main.cpp -o main.exe diff --git a/SimpleCalculator/main.cpp b/SimpleCalculator/main.cpp new file mode 100644 index 0000000..7a71f4a --- /dev/null +++ b/SimpleCalculator/main.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +int main() { + int a, b; + char op; + + // Ask user for input + cout << "Enter expression (example: 5 + 3): "; + cin >> a >> op >> b; + + // Perform calculation based on operator + switch(op) { + case '+': + cout << "Result = " << a + b << endl; + break; + case '-': + cout << "Result = " << a - b << endl; + break; + case '*': + cout << "Result = " << a * b << endl; + break; + case '/': + if (b != 0) + cout << "Result = " << a / b << endl; + else + cout << "Error: Division by zero!" << endl; + break; + default: + cout << "Invalid operator!" << endl; + } + + return 0; // end of program +} diff --git a/SimpleCalculator/main.exe b/SimpleCalculator/main.exe new file mode 100644 index 0000000..9186386 Binary files /dev/null and b/SimpleCalculator/main.exe differ