-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
164 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
# depslib dependency file v1.0 | ||
1681493466 source:d:\nicos code\shell\nshell\nshell\main.cpp | ||
1682249258 source:d:\nicos code\shell\nshell\nshell\main.cpp | ||
"help.h" | ||
"calc.h" | ||
<iostream> | ||
|
||
1681493184 d:\nicos code\shell\nshell\nshell\help.h | ||
|
||
1681999616 source:d:\nicos code\shell\nshell\nshell\help.cpp | ||
1682249424 source:d:\nicos code\shell\nshell\nshell\help.cpp | ||
"help.h" | ||
<iostream> | ||
|
||
1682247462 d:\nicos code\shell\nshell\nshell\calc.h | ||
|
||
1682249520 source:d:\nicos code\shell\nshell\nshell\calc.cpp | ||
"calc.h" | ||
<iostream> | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
<CodeBlocks_layout_file> | ||
<FileVersion major="1" minor="0" /> | ||
<ActiveTarget name="Debug" /> | ||
<File name="help.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> | ||
<ActiveTarget name="Release" /> | ||
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> | ||
<Cursor> | ||
<Cursor1 position="330" topLine="0" /> | ||
<Cursor1 position="613" topLine="7" /> | ||
</Cursor> | ||
</File> | ||
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> | ||
<File name="help.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> | ||
<Cursor> | ||
<Cursor1 position="787" topLine="3" /> | ||
<Cursor1 position="347" topLine="0" /> | ||
</Cursor> | ||
</File> | ||
</CodeBlocks_layout_file> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "calc.h" | ||
#include <iostream> | ||
|
||
void add(double x, double y) | ||
{ | ||
std::cout << x << " + " << y << " = " << x + y << "\n"; | ||
} | ||
|
||
void subtract(double x, double y) | ||
{ | ||
std::cout << x << " - " << y << " = " << x - y << "\n"; | ||
} | ||
|
||
void multiply(double x, double y) | ||
{ | ||
std::cout << x << " * " << y << " = " << x * y << "\n"; | ||
} | ||
|
||
void divide(double x, double y) | ||
{ | ||
if (y != 0) { | ||
std::cout << x << " / " << y << " = " << x / y << "\n"; | ||
} | ||
|
||
else { | ||
std::cout << "NShell encountered an error: Cannot divide by zero.\n"; | ||
} | ||
} | ||
|
||
void calc() | ||
{ | ||
std::string confirm; | ||
|
||
while (true) { | ||
std::cout << "Please type in the first number: "; | ||
double x{ }; | ||
std::cin >> x; | ||
|
||
std::cout << "Please type in the second number: "; | ||
double y{ }; | ||
std::cin >> y; | ||
|
||
while (true) { | ||
std::cout << "Please choose what to do.\n\n"; | ||
std::cout << "1. Add\n"; | ||
std::cout << "2. Subtract\n"; | ||
std::cout << "3. Multiply\n"; | ||
std::cout << "4. Divide\n"; | ||
std::cout << "5. Enter other numbers\n"; | ||
int sel{ }; | ||
std::cin >> sel; | ||
|
||
switch (sel) | ||
{ | ||
case 1: | ||
add(x, y); | ||
break; | ||
|
||
case 2: | ||
subtract(x, y); | ||
break; | ||
|
||
case 3: | ||
multiply(x, y); | ||
break; | ||
|
||
case 4: | ||
divide(x, y); | ||
break; | ||
|
||
case 5: | ||
break; | ||
|
||
default: | ||
std::cout << "NShell encountered an error: Please choose a number between 1 and 5.\n"; | ||
} | ||
|
||
std::cout << "Do you want to re-run? (Y/N): "; | ||
std::cin >> confirm; | ||
|
||
if (confirm == "Y" || confirm == "y" || confirm == "N" || confirm == "n") { | ||
break; | ||
} | ||
|
||
else { | ||
std::cout << "NShell encountered an error: Please type Y or N.\n"; | ||
} | ||
} | ||
|
||
if (confirm == "N" || confirm == "n") { | ||
break; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef CALC_H_INCLUDED | ||
#define CALC_H_INCLUDED | ||
|
||
void add(double x, double y); | ||
void subtract(double x, double y); | ||
void multiply(double x, double y); | ||
void divide(double x, double y); | ||
void calc(); | ||
|
||
#endif // CALC_H_INCLUDED |
This file contains 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
This file contains 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