need help on program...

This is a discussion on need help on program... within the C++ Programming forums, part of the General Programming Boards category; Ive been told to do a program which outputs the following: * ** *** **** ***** I know it involves ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Question need help on program...

    Ive been told to do a program which outputs the following:

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


    I know it involves using three loops that look like this:


    for(int i=1;i<=5;i++)
    {
    for(int j=i;j<=5;j++)
    {
    cout<<" ";
    }
    for(???????)
    {
    cout<<*;
    }
    cout<<endl;
    }

    can someone please tell me if im close, and if so what this third loop needs to contain? ive been trying to do it for a while now, and no matter what i put in that third loop it always runs infinitely.
    thanks~

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    more...

    for some reason when i posted it altered the triangle i needed...
    since it wont let me display, ill descobe it...
    it consists of a block pretty much, where it has 4 spaces and 1 star for the first row, then 3 spaces and 2 stars for the second...etc,etc...pretty much the one displayed, but reversed.
    thanks~

  3. #3
    Unregistered
    Guest
    for(int i=1;i<=5;i++)//which line
    {
    for(int j=i;j< 5;j++) //max 4 spaces per line
    {
    cout<<" ";
    }
    for(int k = 1; k <= i; k++)//max 5 * per line
    {
    cout<<'*';
    //etc.

  4. #4
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    or you could just cheat...


    cout << "*\n";
    cout << "**\n";
    cout << "***\n";
    cout << "****\n";
    cout << "*****\n";
    I came up with a cool phrase to put down here, but i forgot it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21