I'm new to programming, and I need help making a hollow triangle.

This is a discussion on I'm new to programming, and I need help making a hollow triangle. within the C++ Programming forums, part of the General Programming Boards category; program must include the following: ask the user for triangle size triangle size must be between 1 and 20 it ...

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

    I'm new to programming, and I need help making a hollow triangle.

    program must include the following:
    ask the user for triangle size
    triangle size must be between 1 and 20
    it must ask the user if he wants to draw another triangle (Y or N)
    ex:
    enter triangle size: 25
    size between 1 and 20, enter triangle size:5
    *
    **
    * *
    * *
    *****
    would you like to draw another triangle (Y or N): Y
    enter triangle size: 3
    and so on....
    Code:
    //This is my code
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    
    //main prgram
    int main()
    {
        int t_s,        //size of the triangle
            col,        //vertical line
            line;        //horizontal line
        char ans;        //Answer (Yes or No).
    
    
        system("CLS");
        cout << "Take Home #6 by Erick Aguilera - "
             << "The Draw Triangle\n\n";
            do
        {
        cout << "Enter the triangle size: ";
        // size of triangle
        cin >> t_s;
             while ((t_s < 1) || (t_s > 20))            
            {
                cout << "Size must be between 1 and 20, "
                << "Enter the triangle size: ";
                cin >> t_s;
            }
             for(col=1; col <= t_s; col++)
        {    // add one '*' to line as many times as
            // the value of col.
            for(line=1; line<=col; line++)
            {
                cout << "*";
            }
            cout << " ";
            cout << endl;
        }
                cout << "Would you like to draw another triangle "
                << "(Y or N): ";
            cin >> ans;
    
    
        }while (ans == 'Y');
        
        cout << "End Program.\n";
        
    
    
        return 0;
    }

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,623
    Would you like the triangle to be like this:
    Code:
    
    *
    * *
    *   *
    * * * *
    or this:
    Code:
    
       *
      * *
     *   *
    * * * *
    Each shape has its own tricks to make.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    3
    Quote Originally Posted by GReaper View Post
    Would you like the triangle to be like this:
    Code:
    
    *
    * *
    *   *
    * * * *
    or this:
    Code:
    
       *
      * *
     *   *
    * * * *
    Each shape has its own tricks to make.
    Like the first one

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,623
    Quote Originally Posted by eddie1 View Post
    Like the first one
    Ok, then. Say "n" is the current triangle line, starting from 1 ( 0 is the first line, which is only a star ).
    For the hollow part you print a star, (2*n - 1) spaces and a star.
    For the last line, you either print (2*n - 1) stars or star-space-star-etc.
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    3
    Quote Originally Posted by GReaper View Post
    Ok, then. Say "n" is the current triangle line, starting from 1 ( 0 is the first line, which is only a star ).
    For the hollow part you print a star, (2*n - 1) spaces and a star.
    For the last line, you either print (2*n - 1) stars or star-space-star-etc.
    could you show me in the code how, because i'm really new at this and i don't really get it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hollow triangle
    By CProgramming11 in forum C Programming
    Replies: 3
    Last Post: 10-01-2010, 12:29 PM
  2. Replies: 19
    Last Post: 06-23-2010, 02:58 AM
  3. Help making Triangle
    By jensklemp in forum C++ Programming
    Replies: 4
    Last Post: 02-11-2010, 02:59 PM
  4. help making triangle
    By dbzx in forum C Programming
    Replies: 3
    Last Post: 04-05-2009, 01:09 AM
  5. Replies: 14
    Last Post: 11-09-2005, 10:28 PM

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