Thread: Symmetrical Number Pyramid Help Please

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    3

    Symmetrical Number Pyramid Help Please

    Write a C++ program which will ask the user to enter an integer from 1 to 15 and displays a number pyramid (implement input validation). For example, if the input is 4 the output will be as follows:
    * * *1
    * * 2 1 2
    * 3 2 1 2 3
    4 3 2 1 2 3 4
    My professor said we must use nested loops.
    This is what i have so far the 2nd inner loop cause a half pyramid. The 1st inner loop I am trying to make the opposite of the 2nd inner loop. I am unsure you can logically do that however.

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    int main ()
    {
        int n , i , j , k;
        do 
        {
            cout << "Enter an integer between:" << endl;
                cin >> n;
            cout << endl;
        }
        while ( n < 0 || n > 16 );
        
        for ( i = 0 ; i < n ; i++ )
        {
            for( j = 1 ; j = 1 ; i++)
            {
                cout << right << setw(3) << j;
            }
                for ( k = 1 ; k <= i + 1 ; k++ )
                {
                    cout << left << setw(3) << k;
                }
            
            cout << endl;
        }
        
    return 0;
    }
    Last edited by HunterTnTU; 10-11-2011 at 04:03 PM. Reason: Cannot figure out how to get the code tagged properly

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