Ismail Olanrewaju Yes now you got it. That's why here
total = total - no. in loop. So each time total will change and you will get your final result.
It should be like this :-
total = 18 - 9;
total = 9 - 1;
total = 8 - 1;
total = 7 - 1;
total = 6 - 1 = 5
which is your final result.
But if I input 5 digits it won't properly subtract the 5 numbers.. Let's say I input
A Normal subtraction will give us 5 as the answer right? But in this case it's finna be "0 -9 -1 -1 -1 -1 " Which will give us a negative 13 (-13). So that isn't the answer that I want.
How 5? Can you explain me. You are taking input from keyboard. When you will decide from which value you will have to subtract?
You need already given value from which you will have to subtract inputs value.
I think your concept is not clear.
Oh I understand now.. so I have to change my "total " To a fixed amount so therefore when I subtract, it will give me 5.. . I understand now.
I have to make my total like 18 so when I minus 9,1,1,1,1 it will be something like
"18 - 9 - 1- 1-1-1 which will give us a 5... Right?
If I understand correctly then you don't know the total beforehand.
Read the first value outside the loop:
cin >> total;
And then do the subtraction loop as indicated by AJ || ANANT || AC || ANANY || AY