From the course: C Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Repeat some text

Solution: Repeat some text - C Tutorial

From the course: C Essential Training

Start my 1-month free trial

Solution: Repeat some text

(upbeat music) - [Instructor] To make the loop work in your solution, you need a second variable. I've added variable B to the declaration of variable A here at line five. The for loop appears at line 10. Variable B is initialized to zero. The loop repeats while variable B is less than the value of variable A, which is what the user input. And each time the loop repeats, variable B is incremented. The single repeating statement is putchar here at line 11. I added a second putchar statement here at line 12 to terminate the new line, which helps clean up output. Build and run, and I'll type 50, and you see 50 hyphens. I know it's 50 hyphens, I'm not going to count them. Here's my while loop variation for the solution. It also requires a second variable B, which is initialized here at line 10. And you don't have to call it variable B, but you do need a second variable. The while loop repeats, as long as the value of…

Contents