using sentinela to read from file HELP!!

Hi, I have an assignment of reading from a file and using the sentineala int -1 to stop, add the 0 and 1 on different variables and then continue reading.

EX:::: 1111000011110000-1 00001111000111000111-1

This is an HOTEL program where floors=-1 and free rooms=1, and occupatedrooms=0

So I use and array to store the values and started manipulate them like this

for (int i=0;i<len;i++)

while (rooms[i]==-1)




Sorry for the english I'm not pretty good at it.

ANW:::what can I do to reaad the ones add them, read the zeros; add then ,stop and do the same until reach the eof()???
Your logic makes no sense. All the stuff inside the while loop will only happen if rooms[i] is -1. So the tests for rooms[i]==1 and rooms[i]==0 can never be true. So freerooms and occupatedrooms will never be incremented.

Also, the while loop does not change the value of i, or the value of rooms[i]. So if rooms[i] is -1 at the start of the while loop, it will loop for ever.

Last edited on
Topic archived. No new replies allowed.