Line 13,30: These statements do nothing. Just leave them out.
Line 25: If k is the number of passengers on the bus, you don't want to set the number of passengers to 0 at each stop. Move this statement outside the loop. Note that you're already defining k at line 6.
Line 26: You're doing arithmetic with m before you've determined if m is valid.
Line 33-34: If m is invalid, you're going to repeat the cin, but you will use up an iteration of your loop.
So what should I do to control the validity of m? I have no idea how to make {{ -x ≤ [n} ≤ 50 and x refers to the number of passengers on the bus at that time}} this work in my programme.
I'm a total beginner in c++....hardly understand what this question asks for....
Can you show me some steps?
Oh I got it!! Thanks!!
But here's one last thing that confuses me. The question allows us to input the number of people getting on the bus as many as 50, but the capacity of the bus is only 40, so how can I make the sum of people still on the bus at the last stop right?
here's a sample run:
number of stops: 3
number of people get on/off the bus at stop 1: -1
please input again: 7
number of people get on/off the bus at stop 2: 20
number of people get on/off the bus at stop 3: 80
please input again: -15
After the last stop, no. of people still on the bus = 1