Ok so when I run the source code in the 1st image I am able to input the value for a month upon the first iteration of the while loop. However as can be seen on the 2nd image on every subsequent iteration it prints but then skips "Month: " w/o letting me input a value and just prompts me to enter "Total Collection: " again.... Also as per the 2nd image I don't understand why the sentinel value gets run at the end just before it terminates the program as though it's a value I want to input in "Total Collections: " as opposed to just the thing that terminates the program. Any help would be much appreciated thank you..!! PS this is exercise 3.16 in C How to program 8th Edition by Peter & Harvey Dietel
It's because you mix reading strings and numbers.
From the first scanf(), there's left a \n (return) from the user's previous answer.
He typed something+\n, and something gets consumed but not the \n.
The second scanf() reads until \n. This is, it reads nothing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.