program that outputs a letter an x number of times

the idea for the program is that the user inputs a letter and a number and it outputs a line pattern starting from 1 going to their number of their letters.
For example

input:
letter = a
num = 4
output:
a
aa
aaa
aaaa
aaaa
aaa
aa
a

and i am supposed to use a for loop inside a for loop. i have no idea what to do and if somebody could help i would be very appreciative

the idea is to make a for loop that counts the number of lines that has another for loop counting the number of characters with a string variable carrying the printed text
Last edited on
simplify the problem.
you've got three things to do
- count from 1 to n
- print x letters (input: 4 a. output: aaaa)
- count from n to 1
¿can you (pseudo)code any of those?
@ne555
i have this code

#include <iostream>

using namespace std;

int main()
{
int rows;
string letter;
cout << "Enter number of pattern rows" << endl;
cin >> rows;
cout << "Enter chracter to be used in pattern" << endl;
cin >> letter;
cout << endl;
for(int i = 1; i <= rows; ++i)
{
for(int j = 1; j <= i; ++j)
{
cout << letter;
}
cout << "\n";
cout << endl;
}
}

but i cant get the reverse loop to also work with it. I kind of knew what you were talking about but i had to look up how to use the vector i j coding because we weren't taught it
Last edited on
1
2
3
4
for(int K=n; K>0; --K){
   print_x_letters(letter, K);
   std::cout << '\n';
}
Topic archived. No new replies allowed.