Hi.... I'm a beginner at this programming thing and I need some help using nested for loops
this is an assignment i have to do for my class, basically the output should be something like this.. the characters depends on what the user inputs and how many rows the user wants to ouput.

This is my program so far-

#include<iomanip>
#include<fstream>
#include<cmath>
#include<iostream>

using namespace std;

int main()

{
	int num;
	char ch;
	int count, count2;
	
	

	cout<<"Enter the character you wish to use: "<<endl;
	cin>>ch;
	cout<<"Enter the number of rows: "<<endl;
	cin>>num;
	for(int row_A=0; row_A<num; row_A++)
		{
			cout<<ch<<'\n';
		
		}


}

it outputs this so far
*
*
*
*
*

i need it to output this
*
**
***
****
*****

Recommended Answers

All 2 Replies

Please use 'Code Tags' for posting code

to your qs. you will need one more loop, something like

for(int row_A=0; row_A<num; row_A++)
{
  for(int row_B=0;row_B<=row_A;row_B++)
  {
      cout << ch;
  }
  cout << "\n";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.