Hi folks. Before you get the wrong idea, no this has nothing to do with std::accumulate. The assignment I have is about accumulating a number with each entry:
+ 1 = 1
+ 2 = 3
* 2 = 6
/ 3 = 2
and so on...
It's 99% done. I got it to loop how I want and say what I want but I came across an interesting problem as I wrote it that I couldn't find an answer to. Here's the code as I have it so far:
cout << "Enter the operand (+, -, *, o r/): " << endl;
cin >> op;
while (op == '+' || op == '-' || op == '*' || op == '/')
{
accumulate(acc, op, num);
cout << "\nAccumulated value is now: " << acc << endl;
cout << "\n";
cout << "Enter the operand (+, -, *, o r/): " << endl;
cin >> op;
}
}
When I add, as displayed above, it does it's job. But if I try to put in the rest (acc = acc- num, acc = acc * num, and acc = acc / num), the accumulated number stays at 0, no matter what operand I use. The same is true if I use the other operands by themselves: They will do the math as they should, but will stay 0 if the others are added. I don't see the logic behind it. Adding the last three shouldn't affect it since they are separate if statements, but they do. Why is that? Can someone show me how to fix this?
Thank you!