How to print text in multiple rows and columns?

I am new to programming and I wonder if someone could please help me with a program that asks the user to input number of rows and number of columns, and it should print a text in these rows and columns. like this:

Number of rows:
2
Number of columns:
4

And the output should be like this:

text text text text
text text text text


Much appreciated if someone could give me an example on how to do this.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    std::cout << "Nmber of rows: ";
    int rows;
    std::cin  >> rows;
    std::cout << "Number of columns: ";
    int columns;
    std::cin  >> columns;
    for(int i = 0; i < rows; ++i) {
        for(int j = 0; j < columns; ++j)
            std::cout << "text" << ' ';
        std::cout << '\n';
    }
}
Thank you so much for the help MiiNiPaa.
I thought that I had to struggle with both FOR loops and ARRAYS. This is perfect!
Topic archived. No new replies allowed.