Results 1 to 5 of 5

Thread: Triangle using C++

  1. #1
    Join Date
    Oct 2008
    Posts
    47

    Triangle using C++

    Is there anyone who can help me to make a triangle like this? (Must use if and else statements!)

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

    --------------------------------------------------
    Can easily do the following:

    Code:
    # include <iostream> 
    
    using namespace std; 
    
    int main(){
    
    int row, col; 
    
    cout << "Enter col"; 
    cin >> col; 
    
    cout << "Enter row"; 
    cin >> row; 
    
    char a ='*'; 
    
    
    for(int i=1;i<=col;i++){ 
    
    for(int x<=5;x>i;x--){
    
    cout <<a; 
    
    }
    cout <<endl; 
    }
    
    system ( "pause"); 
    return 0; 
    }

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

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: Triangle using C++

    Now it's so long since I've coded in c++, so the code I can not help you.

    But it is surely something to put a boolian to false and then check whether it is false, and set it to true when the stars are obtained. And then do a "goto start" or the like. if you can.

  3. #3
    Join Date
    Oct 2008
    Posts
    47

    Re: Triangle using C++

    Hey, it must have way that I will make this one triangle.

    ++++*
    +++**
    ++***
    +****
    *****

    '+' Should be blank fields!

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Triangle using C++

    Maybe something like:
    Code:
    # include <iostream> 
    using namespace std; 
    int main() 
    {
    
    int row,col; 
    
    cout << "Enter col"; 
    cin >> col; 
    
    cout << "Enter row"; 
    cin >> row; 
    
    char a ='*'; 
    
    for (int i = 1; i <= col, i ++) 
    {
    for (int x = 0, x <col - i; x ++) 
    cout << ""; 
    
    for (int x = 0, x <i, x ++) 
    cout << a; 
    cout << endl; 
    }
    
    system ( "pause"); 
    return 0; 
    }
    What are "row" used for?

    I am not sure that "int x<= 5" makes sense.

  5. #5
    Join Date
    Oct 2008
    Posts
    47

    Re: Triangle using C++

    Thank you for your reply kelfro. It was just what I was looking for. You have the right terms for the "row" but had used it in another task.

Similar Threads

  1. Triangle generator
    By gelsys1208 in forum Software Development
    Replies: 3
    Last Post: 13-10-2010, 04:32 AM
  2. utorrent yellow triangle indicator
    By Rily in forum Windows Software
    Replies: 3
    Last Post: 24-06-2010, 03:44 PM
  3. What is the Code for Floyd's triangle in C ??
    By Silent~Kid in forum Software Development
    Replies: 5
    Last Post: 02-01-2010, 07:43 PM
  4. Want To Print Triangle In C++
    By vishodhan in forum Software Development
    Replies: 1
    Last Post: 08-01-2009, 09:53 PM
  5. Yellow triangle in the taskbar
    By harakim in forum Windows Software
    Replies: 3
    Last Post: 03-10-2008, 03:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,877,885.71385 seconds with 17 queries