Skip to content

Instantly share code, notes, and snippets.

@X-88
Created April 23, 2020 03:37
Show Gist options
  • Save X-88/e7ca9655c03892a76da76e771ed97541 to your computer and use it in GitHub Desktop.
Save X-88/e7ca9655c03892a76da76e771ed97541 to your computer and use it in GitHub Desktop.
Calculator in C++
#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