Thread: stupid pyramid

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    3

    stupid pyramid

    can someone please help me with this stupid thing.. I was not born to be a programmer..
    i have to make this
    *
    **
    ***
    ****
    *****

    using a loop thing..

    for (int k=0; k<5; k++)
    for (int x=-1; x<k; x++)
    cout << "*";
    cout << endl;

    I dont get how to put the spaces in to make it look like a pyramid though.. you guys will say "im not doing your homework for you".. but I could use the help.. if you dont help me Ill fail college and work at mcdonalds for the rest of my life..

    sigh

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    19
    well dont rely on these ppl will help you. (this ppl here only will tell you do it your own) but jeez you got to give him some hint


    Here some example i show you but you have to learn it.


    int main()
    {
    int x,y;
    for (x=1;x<=9;x++) {

    { for (y=1;y<=x;y++)

    cout<<1;
    }
    cout<<endl;

    }



    or


    {

    int x,y,z;



    for (x=1;x<=9;x++) {

    for (z=10;z>=x;z--) {

    cout<<" ";
    }

    { for (y=1;y<=x;y++)

    cout<<" 1";
    }
    cout<<endl;

    }

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >if you dont help me Ill fail college and work at mcdonalds for the rest of my life..
    Hehe. This works just fine, though I question whether it would be accepted.
    Code:
    #include <iostream>
    #include <iomanip>
    
    int main()
    {
      int n;
    
      std::cout<<"Enter the number of lines: ";
      std::cin>> n;
      std::cin.ignore();
    
      for ( int i = 0; i < n; i++ ) {
        std::cout<< std::setw ( n - i ) << std::setfill ( ' ' ) <<"";
        std::cout<< std::setw ( i * 2 + 1 ) << std::setfill ( '*' ) <<""<<std::endl;
      }
    
      std::cin.get();
    }
    And another that would be equally unacceptable, though your instructor would marvel at your fluency with printf.
    Code:
    #include <iostream>
    #include <string>
    #include <cstdio>
    
    int main()
    {
      int n;
    
      std::cout<<"Number of lines: ";
      std::cin>> n;
      std::cin.ignore();
    
      std::string s ( n * 2, '*' );
    
      for ( int i = 1; n > 0; i += 2 )
        std:: printf ( "%*c%.*s\n", n--, ' ', i, s.c_str() );
    
      std::cin.get();
    }
    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    19
    the best way is to learn how to trace the code.. and understand it well .

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    11
    cuz then you can modify it and apply it to any other problems you have.
    I'm not here. This isn't happening

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a half pyramid
    By rightbrainer in forum C Programming
    Replies: 7
    Last Post: 04-21-2009, 01:29 AM
  2. A stupid question...probably
    By Phoenix_Rebirth in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2007, 04:53 PM
  3. Number pyramid
    By Tehy in forum C Programming
    Replies: 7
    Last Post: 05-31-2007, 09:01 AM
  4. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  5. Incredibly Stupid People
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 09-09-2003, 04:12 PM