4 Replies - 354 Views - Last Post: 07 April 2012 - 09:28 AM Rate Topic: -----

#1 Javi_11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 03-March 12

Star triangles

Posted 06 April 2012 - 08:52 PM

My output has to be
*
**
***
****
*****
******
but right now it just shows.
*
*
*
*
*
*

Can someone give me a hint on what I am doing wrong or if I am missing something?


#include <iostream>



using namespace std;



int main()
{
int star = 0;
int row = 6;
do
{
cout << "*";
cout<<endl;
star++;
star = 0;
row--;
}
while ((star <= row) && (row >= 1));

}






Is This A Good Question/Topic? 0
  • +

Replies To: Star triangles

#2 no2pencil  Icon User is offline

  • Original Digital Gansta
  • member icon

Reputation: 4466
  • View blog
  • Posts: 24,916
  • Joined: 10-May 07

Re: Star triangles

Posted 06 April 2012 - 08:58 PM

** Renamed title to be more descriptive **
Was This Post Helpful? 0
  • +
  • -

#3 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1831
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: Star triangles

Posted 06 April 2012 - 09:08 PM

1. Why are you incrementing star on line 17 and immediately setting it back to 0 on line 18?

2. If you want the number of stars to increase on each succeeding row, why are you starting rows at 6 and decrementing it on each succeeding loop?
Was This Post Helpful? 0
  • +
  • -

#4 for3v3rforgott3n  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 17-June 09

Re: Star triangles

Posted 06 April 2012 - 09:52 PM

Remove star = 0; on line 18.
Your loop logic is a bit weird as r.stiltskin said but it should display properly in this instance. Good to know for the future.
Was This Post Helpful? 0
  • +
  • -

#5 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 257
  • View blog
  • Posts: 1,671
  • Joined: 20-September 08

Re: Star triangles

Posted 07 April 2012 - 09:28 AM

View Postfor3v3rforgott3n, on 07 April 2012 - 12:52 AM, said:

Remove star = 0; on line 18.
Your loop logic is a bit weird as r.stiltskin said but it should display properly in this instance. Good to know for the future.

No ... It will not give you the display you wish because right after every star printed you then print a new line.
What you need here is really a loop within a loop ...
The outer loop to handle the number of rows printed
The inner loop to handle the number of stars printed on each row
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1