Created
April 23, 2020 03:37
-
-
Save X-88/e7ca9655c03892a76da76e771ed97541 to your computer and use it in GitHub Desktop.
Calculator in C++
This file contains hidden or 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
#include <iostream> | |
using namespace std; | |
float a, b, r; | |
char key; | |
string spr = "==========================\n"; | |
int main(); | |
void reset() | |
{ | |
system("sleep 2"); | |
system("cls"); | |
main(); | |
} | |
float mul(float x, float y) | |
{ | |
return x * y; | |
} | |
float div(float x, float y) | |
{ | |
return x / y; | |
} | |
float add(float x, float y) | |
{ | |
return x + y; | |
} | |
float sub(float x, float y) | |
{ | |
return x - y; | |
} | |
int main() | |
{ | |
cout << spr << "App Name: Calculator\nCoded by: Zephio\nLanguage: C++\n" << spr << "(*) Mul\n(/) Div\n(+) Add\n(-) Sub\n" << spr << "Choose Operator: "; | |
cin >> key; | |
cout << spr; | |
cout << "Enter Value A: "; | |
cin >> a; | |
cout << "Enter Value B: "; | |
cin >> b; | |
switch (key) | |
{ | |
do | |
{ | |
// mul | |
case char(0x2a): | |
r = mul(a, b); | |
cout << "Result: " << r << endl; | |
reset(); | |
break; | |
// div | |
case char(0x2f): | |
r = div(a, b); | |
cout << "Result: " << r << endl; | |
reset(); | |
break; | |
// add | |
case char(0x2b): | |
r = add(a, b); | |
cout << "Result: " << r << endl; | |
reset(); | |
break; | |
// sub | |
case char(0x2d): | |
r = sub(a, b); | |
cout << "Result: " << r << endl; | |
reset(); | |
break; | |
default: | |
cout << "Invalid choice" << endl; | |
reset(); | |
} | |
while (key != 0); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment