Question: I need help modifying a C++ program: I am trying to write a program that outputs a triangle of code with a certain number of

I need help modifying a C++ program:

I am trying to write a program that outputs a "triangle" of code with a certain number of rows (input by user) and each successive line counts up to that number from one... It's hard to explain, but here's a sample output -- Say a user inputs "5", it should output

12345

1234

123

12

1

I have this part down, but if the number exceeds 9, it should reset back to 0 instead of counting to 10... for instance user inputs "12" it should output:

123456789012

12345678901

1234567890...... and so on.

Here is what I have so far:

int numRows(0), userRows;

// prompts user for and reads in the number of rows

cout << "Enter number of rows: ";

cin >> userRows;

cout << endl;

while (userRows >=1 ) {

while (numRows < userRows && numRows < 9) {

numRows++;

cout << numRows;

}

cout << endl;

userRows--;

numRows = 0;

}

But I am not sure how to make it go back to 0 after 9 when the input is greater than 9... with mine, if a user input 12 mine would output:

123456789101112

1234567891011....

This is what I need help with !!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!