8000 Merge pull request #9 from Samuel-de-Oliveira/newbranch · Benjam007/C-CPP-Programming@900e5fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 900e5fb

Browse files
Merge pull request The-Young-Programmer#9 from Samuel-de-Oliveira/newbranch
Organize windows projects and create a example for Unix like systems
2 parents 1bed3b8 + 7df73cb commit 900e5fb

File tree

18 files changed

+59
-0
lines changed

18 files changed

+59
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Basic Calculator (TUI)
2+
3+
## Compilation:
4+
Use the `m̀ake` command to compile
5+
6+
## Usage
7+
You have 4 operatios `plus` `minus` `times` `devide`
8+
9+
```bash
10+
# The hardest math problem.
11+
./calculator 6 times 3
12+
```
13+
14+
the output should be a simple `18`
15+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <sstream>
4+
5+
// Parse Float
6+
float parseFloat( const std::string &str ) {
7+
8+
/* All the argv arguments is a string
9+
* Because of this is need use a parse
10+
* float function.
11+
*/
12+
13+
std::stringstream ss(str);
14+
float num;
15+
ss >> num;
16+
return num;
17+
18+
}
19+
20+
21+
int main( int argc, char** argv ) {
22+
23+
const std::string Operation(argv[2]); // take the second argument before the "./calculator"
24+
25+
if (Operation == "plus") std::cout << parseFloat(argv[1]) + parseFloat(argv[3]) << '\n'; // Plus
26+
else if (Operation == "minus") std::cout << parseFloat(argv[1]) - parseFloat(argv[3]) << '\n'; // Minus
27+
else if (Operation == "times") std::cout << parseFloat(argv[1]) * parseFloat(argv[3]) << '\n'; // Times
28+
else if (Operation == "divide") std::cout << parseFloat(argv[1]) / parseFloat(argv[3]) << '\n'; // Divide
29+
else std::cout << "Invalid operation\n"; // Invalid operation message
30+
31+
return 0;
32+
33+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
TARGET = calculator
2+
FILE = main.cpp
3+
COMPILER = /usr/bin/g++
4+
5+
.PHONY: all clean
6+
7+
all:
8+
$(COMPILER) $(FILE) -o $(TARGET)
9+
10+
clean:
11+
rm -rf $(TARGET)

0 commit comments

Comments
 (0)
0