Oct 28, 2016 at 1:42am UTC
int main ()
{
Calculator calc;
char c;
double x,y;
cin >> x;
cin.ignore('+'||'-'||'*'||'/'));
cin >> y;
calc.add(x,y);
cout << calc.answer;
return 0;
}
I'm trying to make a calculator that could compute for the answer in a single line input but I dont know how to get the char of the operand. anyhelp?
Oct 28, 2016 at 5:12am UTC
cin >> a >> op >> b;
does not guarantee that the input is from a single line.
Oct 28, 2016 at 5:31am UTC
Only the third example is input from a single line. (The first two involve input from more than one line.)
Oct 28, 2016 at 6:36am UTC
@JLBorges
The OP will always and always try to pick the third one. That is perfectly valid.
Why does the OP have to input more than more line, can you explain?