Hi I'm new to programming and really need some help with my assignment
So, this is the prompt:
Modify this main program so that it prints:
*
**
***
****
***** ****** ******* ******** ********* **********
Write your program so that it's easy to change the height of the triangle.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* Tests function printStars by printing a triangle of stars. */
#include <iostream>
usingnamespace std;
void printStars (int numStars);
/* Prints "numStars" stars to the screen, followed by a <return>. */
main () {
printStars(3);
printStars(2);
printStars(1);
}
void printStars (int numStars) {
/* Prints "numStars" stars to the screen, followed by a <return>. */
int count;
for (count = 0; count <numStars; count ++) {
cout<<"*";
}
cout<<endl;
}
I've been struggling with this assignment for a while, any suggestion would be really appreciated
printStars(n) prints a line with n stars on it. So to print the the triangle, you need to call printStars(1), then printStars(2).... to printStars(10). To make it easy to change the height, put the calls to printStars() in a loop.
This is an example of using one function as a building block for another.
your printStars function looks good. You should make a loop in your main function to print out the stars based on how high the user wants the triangle.
main(){
cout<<"How many rows do you want?";
int n;
cin>>n;