View Single Post
  #1 (permalink)  
Old February 13th, 2006, 11:37 PM
cdbabcock cdbabcock is offline
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default for loop trouble (beginner)

I am trying to output the following pattern:

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

Here is what i have been able to come with:

#include <iostream>
using namespace std;

int main()
{
    int column=16;
    int row=8;

    for (int counter = 0; counter < row; counter++){
        for (int count = 0; count < column; count++){
            if ( count % 2 == 0)
            cout << "*";
            else
                cout << " ";
        }
    cout << endl;
    }
    return 0;
}

I dont know how to get every other row shifted 1 space. The exercise i am doing says to only use 3 output statements

cout <<'*';
cout <<" ";
cout << endl;

I would like to add, this isnt homework. I am trying to learn C++ on my own (and with your help). I have about 8 books on the subject (one is wrox- beginning C++). This particular exercise is out of an old Deitel & Deitel book, C++ How To Progream (3rd Edition).

Please dont just give a solution, try to walk me thru the solution. I am sure its something math related, i just cant figure it out and instead of giving up completly, decided to ask for help.

Thanks
Chris

Reply With Quote