First Semester CS Student Needs Understanding Help In While Loop

Usually I send a message to DreamInCode.net, but the site seems to be down now. I am the first CS student at De Anza. I really don't understand what lineCount = 1 is; in the else statement. I know what he does when I delete a statement, but I do not understand this. If I could ask someone to explain this to me, perhaps in a different way that the book will simply skip, I would really appreciate it.

#include <stdio.h> int main (void) { int num; int lineCount; printf ("\nEnter a starting number to decend between 1 and 100: "); scanf ("%d", &num); if (num > 100) num = 100; lineCount = 0; while (num >= 0) { if (lineCount < 10) lineCount++; else { printf ("\n"); lineCount = 1; // this line here is what I don't understand } printf ("%4d", num--); } return 0; } 
+4
source share
1 answer

lineCount does not actually count lines. It counts the number of numbers you typed in the current line.

When this reaches 10, it breaks the line and starts a new one, resetting the counter to 1. 1 instead of 0, because you put another number on a new line.

+5
source

Source: https://habr.com/ru/post/1383370/


All Articles