I tried to make my first C++ Calculator with Multiple inputs not just num1 and num2, but for example; "10 - 8 results to -18" I tried changing the 'result = 0;' to result; only but it doesn't get me where I want. Do I need to mess up with the whole code or create new ways to like store multiple numbers?
what exactly did you type in?
seems like you would type
2 //number of numbers
10 //number
+ //first operation
//result = result+10 (0+10 = 10)
8 //
- //operation
result = 10-8 = 2
right?
for THAT to work, you have to remove this line:
//if(lc < numberOfitems)
so it was almost correct. but the comment "You should only use (1) Operation all the way." is not right; and it can't be right with this logic, you MUST allow different operations to code it this way as per the example input I gave.
its almost there so a tweak seems appropriate.
if you don't like the change I made, you need to find a way to 'seed' it. If you re-read what I said, you will see that the problem you were having is that result is not set to the first number input. you can do something kind of ugly but simple here:
if(lc == 1) result = number else (do what you were doing)
this is logically the same as adding the first number to result (which is what I did).
you can also do something fancy; if you took a page from reverse polish calculators and used stacks and queues to process the input it would work (with a fair amount of surgery and rewriting). That is a wee bit overkill given that you can get from where you are to where you want to be with a statement or two. But most advanced calculators will use some sort of heavy parsing of the input, so if you plan to build something like a full blown scientific calculator, you may want to rethink the approach.