Thevenin99
Thevenin99

Reputation: 33

C++ formatting to display numbers in a row instead of a column

This is part of a larger code I am doing but I have a question about the formatting. For this part I am using the following for loop which displays the numbers that are less or equal to rNumber.

My only question is how can I make it display the numbers in a row instead of a column since when I run the program, if for example rNumber is 5, it will display:

1

2

3

4

5

What I want is for it to display it like this : 1 2 3 4 5

else if (mNumber < rNumber)
    {
        cout << "\nYour number is too low, try again!. Here is a hint, pick between these!:" << endl;

        for (int i = ++mNumber; i <= rNumber; i++)
        {

            cout << i << endl;
        }
    }

Upvotes: 0

Views: 1093

Answers (1)

Lucas Hendren
Lucas Hendren

Reputation: 2836

Get rid of endl and just add a string with a space in between

 cout << i << " ";

endl stands for end of line.

Upvotes: 1

Related Questions