Stars Equation
Sep 20, 2016 at 3:08am UTC
Prompt the user to enter a positive integer and create a pattern of “stars”. I am having a hard time displaying and working the bottom half. The top should reflect the bottom but lowering stars (9 stars to 0 instead of 1 to 9) (Don't worry about the colors)
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
int main()
{
int starsPerLine = 0;
cout << "Enter a positve number:\t" ;
cin >> starsPerLine;
cout << endl;
cout << endl;
for (int line = 1; line < starsPerLine; line++)
{
for (int stars = 1;
stars <= line;
stars++)
cout << '*' ;
cout << endl;
}
for (int line = starsPerLine; line < 0; line--)
{
for (int starsTwo = 9;
starsTwo <= line;
starsTwo--)
cout << '*' ;
}
return 0;
}
Sep 20, 2016 at 3:15am UTC
What is your expected program output?
Sep 20, 2016 at 1:18pm UTC
check your line 18,
line<0;//less?
@SakurasouBusters I think (s)he is trying to make somewhat like this
The top should reflect the bottom but lowering stars
Enter a positve number: 9
*
**
***
****
*****
******
*******
********
*********
********
*******
******
*****
****
***
**
*
Sep 21, 2016 at 4:41pm UTC
Hello salomonthesav,
I played with the program until I came up with this:
1 2 3 4 5 6 7
for (int line = 1; line < starsPerLine; line++)
{
for (int starsTwo = starsPerLine - 2; starsTwo >= line; starsTwo--)
cout << '*' ;
cout << endl;
}
The
starsTwo = starsPerLine - 2
is what I setteled on when - 1 did not work the way I wanted.
Notice the first for loop is like any normal for loop it is really just a counter.
Hope that helps,
Andy
Topic archived. No new replies allowed.