So far I did this but I have to use cin.peek and I'm not really sue how it works. I have to delete the line(s) I'm currently using to read in the user's input, and in its place put the following code (to ignore all initial whitespace on the input stream):
#include <cmath>
// pow()
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <string>
using std::string;
int main() {
double a; // to hold the user's first real number
double b; // to hold the user's second real number
string operation; // to hold the user's operation
cout << "Please enter a real number: ";
cin >> a;
cout << "Please enter an operation (+, - , *, /, **): ";
cin >> operation;
cout << "Please enter another real number: ";
cin >> b;
cout << endl;
cout << a << " " << operation << " " << b << " = ";
if ( operation.compare("+") == 0 )
cout << a + b;
elseif ( operation.compare("-") == 0 )
cout << a - b;
elseif ( operation.compare("*") == 0 )
cout << a * b;
elseif ( operation.compare("/") == 0 )
cout << a / b;
elseif ( operation.compare("**") == 0 )
cout << pow(a,b);
else
cout << "ERROR: Operation not supported";
cout << endl;
return 0; // success
}
Well for starters you are going to want to check if the next character is a letter or a number. If it is a letter you can safely say they want log or natural log. Otherwise they are doing an expression like 4 * 5. Then get the desired result based on the chosen operation.
You just mashed the if statement I suggested into smac's code. For that to work it would have to be in the do math function and change the first_operand to f.
Also I would suggest applying the code to your original and not just copy/paste. If you do the copy/paste method you may not understand everything.
BY the way did you look at the link JLBorges linked earlier? He helped one of your classmates with getting the equations now you just need to return the result based on the operator.