Here is the pseudo code:
// pseudocode
cin >> token;
if token.begins_with('#')
cin >> right
result = sqrt(right)
else
left = token.convert_to_numeric_value()
cin >> op >> right
switch (op) {
// as you had originally
}
}
I want to get that into my existing code which is:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
cout<<"Welcome to the Rikard Eskilsson calculator!\n";
cout<<"Please enter the mathematical problem you wish to solve\n";
double left, right;
char oper;
double result;
while (cin >> left >> oper >> right) {
switch (oper) {
case '+': result = left + right;
break;
case '-': result = left - right;
break;
case '*': result = left * right;
break;
case '/': result = left / right;
break;
case '^': result = pow (left, right);
break;
default : cout << "Incorrect value '" << oper << "'" << endl;
continue;
}
cout << result << endl << endl;
}
return 0;
}
The help is urgent and much appreciatet!:c-smile:


Sign In
Create Account

Back to top









