Help writing a for loop code
Oct 22, 2012 at 8:01pm UTC
I am completely lost. I have to write a program using
for loops and it must create the figure below:
<<<<<< ############ >>>>>>
<<<<< ##########** >>>>>
<<<< ########**** >>>>
<<< ######****** >>>
<< ####******** >>
< ##********** >
************
Each output statement must write only one character constant. Also, states before writing the code, write the pseuodocode for the algorithm for the program, not sure how to start with that.
Oct 22, 2012 at 8:06pm UTC
Writing pseudo code will certainly help. Pseudocode is basically code without syntax, or code in plain english.
Something like
loop for number of lines
{
loop for number of "<"
loop for number of "#"
...
...
decrement number of "<"
}
Oct 22, 2012 at 8:31pm UTC
Here you are :)
1 2 3 4 5 6 7 8 9 10
for ( int i = 0; i < 7; i++ )
{
for ( int j = 0; j < 7 - i - 1; j++ ) std::cout << '<' ;
for ( int j = 0; j < i + 1; j++ ) std::cout << ' ' ;
for ( int j = 0; j < 12 - 2 * i; j++ ) std::cout << '#' ;
for ( int j = 0; j < 2 * i; j++ ) std::cout << '*' ;
for ( int j = 0; j < i + 1; j++ ) std::cout << ' ' ;
for ( int j = 0; j < 7 - i - 1; j++ ) std::cout << '>' ;
std::cout << std::endl;
}
Oct 22, 2012 at 8:41pm UTC
Thank you very much!
Topic archived. No new replies allowed.