help with this sort of problem i dont understand what they want

Write a brief piece of code (not a complete program) that displays the numbers 1 through n on a screen, with only 5 numbers per line. The numbers should be spaced evenly as shown below for the case of n=19:
I am assuming we need to use while loops
You need to #include <iomanip> to use setw(int)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int number;                          // Our variable for max count
    int n;                                // If you need to dynamically space
    int padding = 0;               // for dynamic spacing, 
                                            // otherwise set as 2
     
    cin >> number;
    n = number;
    
    //to figure out how much to pad so as to equally format
    do {
        int digit = n % 10;
        padding++;
        n /= 10;
    } while (n > 0);

    //output the numbers
    for(int i = 1; i <= number; i++)
    {
        cout << "n=" << setw(padding) << i;
        if(i%5 == 0)
            cout << endl;
    }


I think this is what you need, not exactly sure. The biggest problem people have in programming classes is reading & problem solving.

Hope it helps
Topic archived. No new replies allowed.