Hi my name is Chris and I would like to sincerely ask someone for help with a current project my Professor has assigned. I have written and compiled/executed a working calculator which performs 4 functions(+,-,/,*),but I need assistance in regards to writing code that will in turn work out some of the other mathematical functions I have been tasked with incorporating into said project.
Any assistance would be greatly appreciated and a lifesaver. Thanks in advance.
Here's the formal project:
Start after completing Chapter 3 in class and myprogramming lab:
Write a program that follows the steps below
1) Define two double variables a and b
2) Ask user to enter 2 numbers and store the user inputs in a and b respectively
2) Perform and output results of ten mathematical operations:
a+b, a-b, a*b, a%b, a^b, square root of a^b, log of b to the base a, integer division (a/b), floating point division (a/b), squareroot of (a^2+b^2)
For some of the above calculations, you need to use static_cast to convert the variables in the correct format. For example the modulus operation works only with integers but your variables a and b are defined as double.
Here's the code I've written so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
using namespace std;
int main() {
double a, b;
int option;
while (option != 10) {
cout << "Please select two integers to compute (ex. \" 5 9 \"): ";
cin >> a >> b;
cout << endl;
cout
<< "1. Add" << endl
<< "2. Subtract" << endl
<< "3. Multiply" << endl
<< "4. Divide" << endl
<< "5.Mod " << endl;
<< "6."
cout << endl << "Please select an option: ";
cin >> option;
cout << endl;
switch (option) {
case 1:
cout << a << " + " << b << endl;
cout << "Sum: " << (a + b) << endl;
break;
case 2:
cout << a << " - " << b << endl;
cout << "Difference: " << (a - b) << endl;
break;
case 3:
cout << a << " * " << b << endl;
cout << "Product: " << (a * b) << endl;
break;
case 4:
cout << a << "/" << b << endl;
cout << "Quotient: " << (a/b) << endl;
break;
case 5:
break;
default:
break;
}
cout << endl;
}
}
|