For loop Design 
Author Message
 For loop Design

     I need help.  I have an excersize that asks the user
to input a number and prints a design, For example, if
the program asks how many columns and rows you would
like.  let's just say we input 5,  it should print:

*
**
***
****
*****
     I have been at this thing for about a week and and
cannot figure out where to position the brackets.  Here
is my code,  make the necessary adjustments or just geiv
eme a hint on how to position the brackets:

     #include <iostream>

using namespace std;

int main()
{

int row, column;

cout<< "Welcome to John's program!"
        << endl;

cout << "How many columns and rows would you like: ";
                cin >> column;

         cout << endl;                                    
        for ( int i = 1; i <= column; i++ )
             cout << " *" << endl;
        {

                 for ( int j = 1; j <= column; j++ )
                        cout << " *";  
                        }

                        cout << endl << endl;

        return 0;
        }            

       ******** THANK YOU FOR YOUR HELP.**********



Tue, 18 Oct 2005 07:07:39 GMT  
 For loop Design

Quote:

>      I need help.  I have an excersize that asks the user
> to input a number and prints a design, For example, if
> the program asks how many columns and rows you would
> like.  let's just say we input 5,  it should print:

> *
> **
> ***
> ****
> *****
>      I have been at this thing for about a week and and
> cannot figure out where to position the brackets.  Here
> is my code,  make the necessary adjustments or just geiv
> eme a hint on how to position the brackets:

>      #include <iostream>

> using namespace std;

> int main()
> {

> int row, column;

> cout<< "Welcome to John's program!"
>         << endl;

> cout << "How many columns and rows would you like: ";
>                 cin >> column;

>          cout << endl;
>         for ( int i = 1; i <= column; i++ )
>              cout << " *" << endl;
>         {

>                  for ( int j = 1; j <= column; j++ )
>                         cout << " *";
>                         }

>                         cout << endl << endl;

>         return 0;
>         }

Make sure you format your code consistently.  A good IDE or text
editor should take care of much of this for you.  Adjusting the
indentation on your code should make the layout a bit clearer:

    // This loop contains only one statement
    for ( int i = 1; i <= column; ++i )
        cout << " *" << endl;

    // This scope block is not contained in a loop.
    {
        for ( int j = 1; j <= column; ++j )
            cout << " *";
    }

    cout << endl << endl;

Does this help you understand your problem?

--
Craig Powers
MVP - Visual C++



Tue, 18 Oct 2005 21:36:29 GMT  
 For loop Design
If I understand your task correctly, the second for loop should be
for (int j = 1; j <= i; j++)

or else you will get the same number of columns in each row.



Quote:
>      I need help.  I have an excersize that asks the user
> to input a number and prints a design, For example, if
> the program asks how many columns and rows you would
> like.  let's just say we input 5,  it should print:

> *
> **
> ***
> ****
> *****
>      I have been at this thing for about a week and and
> cannot figure out where to position the brackets.  Here
> is my code,  make the necessary adjustments or just geiv
> eme a hint on how to position the brackets:

>      #include <iostream>

> using namespace std;

> int main()
> {

> int row, column;

> cout<< "Welcome to John's program!"
> << endl;

> cout << "How many columns and rows would you like: ";
> cin >> column;

> cout << endl;
> for ( int i = 1; i <= column; i++ )
>      cout << " *" << endl;
> {

> for ( int j = 1; j <= column; j++ )
> cout << " *";
> }

> cout << endl << endl;

> return 0;
> }

>        ******** THANK YOU FOR YOUR HELP.**********



Wed, 19 Oct 2005 19:33:24 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. For loop design ( Brief Lesson )

2. For loop design part two

3. For loops into for loops

4. Loop or Loops in "C"

5. (Newbie) My Loop Isn't Looping - Aargh!

6. SEMA - WHILE loop in a FOR loop !

7. For loops into for loops

8. wanted - C and/or Fortran source for 24-loop Livermore Loops

9. My Loop Now Loops! Thanks!

10. process loops but 'context' doesn't show me where it loops

11. Loop of loops. Any nice solution?

12. hate the do-while loop (Re: ugly loop; hate the ! operator)

 

 
Powered by phpBB® Forum Software