Loop Program beginner Help

Its an assignment that ive been stuck on for a day, please help.

Create a C++ program that generates the following display based on user input:

Output should display:
Enter # of times to display:¨3
Hello Hello Hello
b. Use a loop .
c. Important: for every five items displayed, skip a line in your display:
Output should display:
Enter # of times to display:¨12
Hello Hello Hello Hello Hello
Hello Hello Hello Hello Hello
Hello Hello
Its an assignment that ive been stuck on for a day, please help.

You've been stuck on this for a day with 0 progress? Surely you must have done something. Please show us what you got so far, use code tags for the code - http://www.cplusplus.com/articles/jEywvCM9/
#include <iostream>
using namespace std;

i got it to display but cant figure out how to make only display five hellos per line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
	unsigned n, i = 1;
	cout << "Enter # of times to display: " ;
	cin >> n ;
	
	do
	{
		cout << "Hello ";
		i++;
	}
	while( i <= n );
	
	return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

using namespace std;

int main() {

	unsigned n, i = 1, counter = 0; // create a counter
	cout << "Enter # of times to display: ";
	cin >> n;

	do
	{
		cout << "Hello ";
		i++;
		counter++; // increment it each iteration

		if (counter == 5){ // once it hits 5, you've printed out 5 hello's
			cout << "\n"; // make a new line
			counter = 0; // put it back to 0 so you can count to 5 again
		}
	} while (i <= n);
	
	return(0);
}
you are Awesome, Thank you so much.
Topic archived. No new replies allowed.