Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions SimpleCalculator/README.md
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions SimpleCalculator/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
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
}
Binary file added SimpleCalculator/main.exe
Binary file not shown.