Outputting new lines for each 10

The user is asked to type in a character and a number. The character will then be printed out that many times, but only 10 characters per line. If first they type in 7 and then the next time around they type in 12, only 3 can go on one line then 9 on the next. I'm not sure how to manipulate my program to do this.

while ( number > 0)
{
cout << endl;
cout << "please enter a positive integer" << endl;
cin >> number;
if (number > 0)
{
cout << "please enter a character" << endl;
cin >> character;
cout << endl;



for (int i = 1; i <= number; i++)
{
cout << character;
if (i % 10 == 0)
cout << endl;
}
}
You will need to have a number that is used throughout the entire while loop. Try going from that and see what you get.
Where would I put this in the while loop so that it doesn't mess up the rest of the program. And do I need to declare a different variable that is set equal to 10?
No, you would have one variable that would be 0. For every character you print, you add one to the variable. When the variable == 10, you print a newline, then carry on.
Tested and it works, please study it!! YOU MUST LEARN FROM THIS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>

using namespace std;

int main()
{
     int number = 0, count = 0;
     char character;

     cout << "Please enter a positive integer and a character: ";
     cin >> number >> character;

     if(number > 0)
     {  
          for(int i = 1; i <= number; i++)
          {
               cout << character;
               count++;

               if(count == 10)
               {
                    cout << endl;
                    count = 0;
               }
                    
          }
     }
}
Topic archived. No new replies allowed.