Thread: Symmetrical Number Pyramid Help Please

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    3
    I forgot to say that the "*"s are not part of the out put they are just to keep the spaces for some reason the spaces went away and this happened:
    1
    2 1 2
    3 2 1 2 3
    4 3 2 1 2 3 4
    Sorry for that confusion I should of clarified that first.

  2. #2
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    No problem, you would go about it the same way. Also, I noticed your while loop is not doing what you think it's doing, you need brackets.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    3

    Update * Close but no cigar*

    So, I have tweaked it some and now I have it giving the out put
    1
    212
    23123
    2341234

    I am having a major pain trying to figure out how to make the 2nd inner loop reverse the number order and make the out put take on the form of a triangle. Maybe its because of frustration.

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    int main ()
    {
        int n , i , j , k;
        
            cout << "Enter an integer between 1 and 15:" << endl;
                cin >> n;
            cout << endl;
        
        while ( n < 0 || n > 16 )
        {
            cout << "Invalid input! Input must be between";
        }
        
        for ( i = 0 ; i < n ; i++ )
        {
            for( j = 2 ; j <= i + 1 ; j++)
            {
                cout << setw(3) << j;
            }
                for ( k = 1 ; k <= i + 1 ; k++ )
                {
                    cout << setw(3) << k;
                }
            
            cout << endl;
        }
        
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Star Pyramid
    By subhadeepgayen in forum C Programming
    Replies: 2
    Last Post: 08-10-2010, 05:16 AM
  2. [ask]pyramid number with loop
    By nitediver in forum C Programming
    Replies: 2
    Last Post: 10-13-2009, 07:57 AM
  3. Number pyramid
    By Tehy in forum C Programming
    Replies: 7
    Last Post: 05-31-2007, 09:01 AM
  4. Making a pyramid of Xs
    By Tride in forum C++ Programming
    Replies: 8
    Last Post: 12-12-2003, 05:14 PM
  5. stupid pyramid
    By nikki19 in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2002, 11:33 PM