Lost on final project for intro class

Trying to get output that looks like this:

Enter number of rows (>0): -4
Invalid entry – try again!
Enter a positive integer: 4
___*
__***
_*****
*******

Getting output that looks like this:
___**
__*
_

Can anyone point me in the right direction?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;

void changeRows(int);

int main(){
	
	int nrows;
	
	cout<<"Enter number of rows (>0): ";
	cin>>nrows;
	while (nrows < 0){
		cout<<"Invalid entry - try again! ";
		cin>>nrows;
	}
	
	changeRows(nrows);
	
	return (0);
}

void changeRows (int nrows){
	int j=1;
	
for (int i = 1; i < nrows; i++){
	cout<<"_";
}
for (int k = nrows-j; j < k; j++){
		cout<<"*";
	}
cout<<endl;
	if (nrows > 1){
		changeRows(nrows-1);
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

void print_row( int row_num, int num_total_rows ) // first row is row #1
{
    const int num_asterisks = row_num*2 - 1 ;
    const int num_underscores = num_total_rows - row_num ;

    // first print the underscores
    for( int i = 0 ; i < num_underscores ; ++i ) std::cout << '_' ;

    // then print the asterisks
    for( int i = 0 ; i < num_asterisks ; ++i ) std::cout << '*' ;

    std::cout << '\n' ; // and finally a new line
}

int main()
{
    int nrows = 15 ;
    // ...

    // print the rows [1 ... nrows ] one by one
    for( int r = 1 ; r <= nrows ; ++r ) print_row( r, nrows ) ;
}
THANK YOU!

makes me feel dumb i spent 2+ hours floundering, and yours makes so much logical sense.

thanks :)
Registered users can post here. Sign in or register to post.