calc/main.cpp

97 lines
2.6 KiB
C++
Raw Normal View History

2021-02-05 21:03:19 -06:00
#include <iostream>
2021-06-16 15:21:47 -05:00
#include <string>
#include <math.h>
2021-02-05 21:03:19 -06:00
using namespace std;
2021-06-16 15:21:47 -05:00
string version = "2.0";
2021-06-16 15:21:59 -05:00
bool inDev = false;
2021-06-16 15:21:47 -05:00
int main() {
cout << "David Calc" << endl;
cout << "Version " << version << endl;
if (inDev) {
cout << "Development build" << endl;
}
cout << "1 - +" << endl;
cout << "2 - -" << endl;
cout << "3 - *" << endl;
cout << "4 - /" << endl;
cout << "5 - Square Root" << endl;
cout << "6 - /R" << endl;
cout << "Choose an operation:" << endl;
string op;
cin >> op;
if (op == "1") {
cout << "+" << endl;
cout << "Addend 1:" << endl;
float num1;
2021-02-05 21:03:19 -06:00
cin >> num1;
2021-06-16 15:21:47 -05:00
cout << "Addend 2:" << endl;
float num2;
2021-02-05 21:03:19 -06:00
cin >> num2;
2021-06-16 15:21:47 -05:00
float result = num1 + num2;
cout << "Sum: " << result << endl;
} else if (op == "2") {
cout << "-" << endl;
cout << "Minuend:" << endl;
float num1;
2021-02-05 21:03:19 -06:00
cin >> num1;
2021-06-16 15:21:47 -05:00
cout << "Subtrahend:" << endl;
float num2;
2021-02-05 21:03:19 -06:00
cin >> num2;
2021-06-16 15:21:47 -05:00
float result = num1 - num2;
cout << "Difference: " << result << endl;
} else if (op == "3") {
cout << "*" << endl;
cout << "Factor 1:" << endl;
float num1;
2021-02-05 21:03:19 -06:00
cin >> num1;
2021-06-16 15:21:47 -05:00
cout << "Factor 2:" << endl;
float num2;
2021-02-05 21:03:19 -06:00
cin >> num2;
2021-06-16 15:21:47 -05:00
float result = num1 + num2;
cout << "Product: " << result << endl;
} else if (op == "4") {
cout << "/" << endl;
cout << "Dividend:" << endl;
float num1;
cin >> num1;
cout << "Divisor:" << endl;
float num2;
cin >> num2;
if (num2 == 0) {
cout << "Division by zero error!";
} else {
float result = num1 / num2;
cout << "Quotient: " << result << endl;
}
} else if (op == "5") {
cout << "Square Root" << endl;
cout << "Value:" << endl;
float num;
cin >> num;
float result = sqrt(num);
cout << "Square root: " << result << endl;
} else if (op == "6") {
cout << "/R" << endl;
cout << "Note: Ony integers (full numbers) are accepted." << endl;
cout << "Dividend:" << endl;
int num1;
2021-02-05 21:03:19 -06:00
cin >> num1;
2021-06-16 15:21:47 -05:00
cout << "Divisor:" << endl;
int num2;
2021-02-05 21:03:19 -06:00
cin >> num2;
2021-06-16 15:21:47 -05:00
if (num2 == 0) {
cout << "Division by zero error!";
} else {
int result = num1 / num2;
int mod = num1 % num2;
cout << "Quotient: " << result << " R" << mod << endl;
}
} else {
cout << "Invalid operation." << endl;
main();
2021-02-05 21:03:19 -06:00
}
return 0;
}