wht bout a triangle

This is a discussion on wht bout a triangle within the C++ Programming forums, part of the General Programming Boards category; how to make a Triangle i want somthg like this Code: * *** **** ****** plz help me...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    31

    wht bout a triangle

    how to make a Triangle
    i want somthg like this

    Code:
             *
           ***
          ****
        ******
    plz help me

  2. #2
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Edit-
    Okay show me your atempt then I'll help you, you need to try.
    If you ever need a hug, just ask.

  3. #3
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    *cough cough HOME WORK cough cough *

    I will tell you it has to do with for loops, and an offset counter.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  4. #4
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Use nested loops and think about how each time a space is replaced by a *.
    Last edited by CheesyMoo; 03-25-2003 at 04:06 PM.
    If you ever need a hug, just ask.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    31
    ok so this is wht i did so far but then how do i account for the spaces??

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
    	int n, r, c;
    	char s;
    	cout << "Enter # of rows: " << flush;
    	cin  >> n;
    	cout << "Enter a character: " << flush;
    	cin  >> s;
    
    	r = 1;
    	
    	while (r <= n)
    	{
    		
    		c= 1;
    		while (c <= r)
    		{
    			cout << space;
    			cout << s;
    			c++;
    		}
    		r++;
    		cout << endl;
    	}
    	return 0;
    }

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    31
    o the
    Code:
    cout << space;
    shouldnt be there!!

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    In C/C++ space is a char, ' '. To make it more visual substitue a # for every space you need to use.

    *
    **
    ***
    ****

    or

    ####
    ###*
    ##**
    #***
    ****

    or

    ###*
    ##**
    #***
    ****

    or

    ##*
    #***
    *****

    or

    ##*
    #***
    *****
    #***
    ##*

    depending on what type of triangle you are trying to build. When you describe in English how to solve one of the above for max of 7 *s, then you can try to change the English into C/C++. The biggest problem in writing code is often how to solve the problem without using code. The essential C/C++ stuff can be done with the top triangle. The last one requires a little more thought, but it's basically the same problem.

    Hint: let the first loop control the line and the second loop the number of # and * to print. Develop a method to relate the line number, number of #, and number of * as needed to solve each triangle, building on what you did for each of the preceding triangles.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursive Triangle Function
    By w2look in forum C Programming
    Replies: 14
    Last Post: 11-13-2010, 01:31 PM
  2. Right Triangle Program
    By BSmith4740 in forum C# Programming
    Replies: 9
    Last Post: 02-26-2008, 11:24 PM
  3. Stupid Logic Problem Need Outside Viewpoint
    By RP319 in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2005, 09:59 PM
  4. Just in case: "Odd" Triangle Challenge (for me)
    By BB18 in forum C Programming
    Replies: 3
    Last Post: 10-09-2004, 12:02 AM
  5. Determining a Triangle using get and pointer
    By naynay in forum C Programming
    Replies: 7
    Last Post: 04-11-2003, 05:55 AM

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