how to make a Triangle
i want somthg like this
plz help meCode:* *** **** ******
how to make a Triangle
i want somthg like this
plz help meCode:* *** **** ******
Edit-
Okay show me your atempt then I'll help you, you need to try.
If you ever need a hug, just ask.
*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.)
Use nested loops and think about how each time a space is replaced by a *.
Last edited by CheesyMoo; 03-25-2003 at 05:06 PM.
If you ever need a hug, just ask.
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; }
o the
shouldnt be there!!Code:cout << space;
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.