Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g Database Administrator Implementation And Administration

Authors: Gavin Powell, Carol McCullough Dieter

2nd Edition

1418836656, 9781418836658

More Books

Students also viewed these Databases questions

Question

What types of intervention do your different clients need from you?

Answered: 1 week ago

Question

Understanding of the different individuals and their background

Answered: 1 week ago