the typical question which ask user to display THIS

*
**
***
****
*****
******
*******
********
*********
**********

using a single cout<<"*" & cout " " with the help of for loops ONLY. :)


ive come to this this prgram but can anyone tell me where i am going wrong and how to correct this error pls!!! :o

#include <iostream.h>
#include <conio.h>
int main()
{
int a,b=1,c=10;

for ( a=10 ; a >=0  ; a--)
	{

   for (  ; b>0 ; b--)
   	{
      cout<<"*";
      }

   for (  ; c>0  ; c--)
   	{
      cout<<" ";
      }
   }
getch();
return 0;
}

whats wrong here!!!!

THE PROBLEM CONTINUES ON.....but for now i need help till here :cry:

First thing I see on quick glance is you need an endline command at the end of the for loop.

Oh yeah, also your b and c variables are only initialized to work the first time through. After the first run b and c are equal to zero and therefore those two nested for loops will do nothing. I am heading off to class so I can't fix the problem for you right now but that is whats going to wrong. You need to find a way to reinitialize b and c for every pass through.

Hi....I am a c++ begginer and i hav a solution for ur problem of ur program...Check out the program I wrote..the program is below...Plz message me if ur problem is solved or if u want any help...

#include<iostream.h>

#include<conio.h>

void main()

{

    int i, j;

    for(i=0; i<10; i++)

    {

        for(j=0; j<=i; j++)

            cout<<'*';

        cout<<endl;

    }

    getch();

}

Edited 3 Years Ago by happygeek: fixed formatting

THANX A LOT ETXREME!!!!! :o

but as our forum admin says u shud not help people do their homework!!!


definetly ive been tempted to copy ur program..........BUT !!!!!


as jasweb pointed out i must some re-initialise b and c to one less and one greater value !!!!!........but where exactly in the loops???? :mad:


pls tach me how to do that.....coz more important than assignment marks is that i understand how to do this tpe of stuff.......:?:

Just Extreme's code a little tidied up for Dev C++
Hope you can see the flow of things.

// Dev C++ code

#include <iostream>

using namespace std;

int main()
{
  int k, m;
  
  for(k = 1; k <= 10; k++)
  {
   // outputs 1,2,3,...,10 stars 
   for(m = 0; m < k; m++)
      cout << "*";
   // end each inner loop with a new line 
   cout << endl;
  }
  cin.get(); // wait 
  return 0;
}

Just Extreme's code a little tidied up for Dev C++
Hope you can see the flow of things.

// Dev C++ code

#include <iostream>

using namespace std;

int main()
{
  int k, m;
  
  for(k = 1; k <= 10; k++)
  {
   // outputs 1,2,3,...,10 stars 
   for(m = 0; m < k; m++)
      cout << "*";
   // end each inner loop with a new line 
   cout << endl;
  }
  cin.get(); // wait 
  return 0;
}

AHHH!!......so he's using the first loop variable in the test expression of the second loop!!!!!!!! :mrgreen:
NOW I GET IT!!!!!!!!!!!!!!!!!!!!!!!

:SMOOCH: :SMOOCH: !!!!!!!!

THNX ALOT PPL.......u solved alot of headache............esp. u EXTREME..........for clarifying the problem solvin technique.....and all others who helped me understand this simple problem...thnx alot :o


THIS FORUM ROX!!!! :evil:

This question has already been answered. Start a new discussion instead.