Home > Software design >  While loop does not print the requested amount of lines
While loop does not print the requested amount of lines

Time:09-08

still very new to C and trying to understand this better. The instruction is to input a certain number of lines using a while loop, but mine appears to only print a total of 10 lines never what I have instructed to print. What am I missing for it to print only what I input?

 int numLines;
printf("Enter lines: ");
scanf("%d", &numLines);
aroundTheWorld(numLines);

    //First line
    printf("Around the world,\n");
    //Repeating lines  
    while(numLines < 10)
    {
    printf("around the world,\n");
    numLines  ;   
    }
    // applies a full stop
    printf("around the world.\n");

    }

CodePudding user response:

Instead of this condition in the while statement with the magic number 10

while(numLines < 10)

write for example

while ( 0 < numLines-- )
{
    printf("around the world,\n");
}
  • Related