...

View Full Version : Help!



wargis
04-25-2004, 03:26 PM
g'day peoples,
im new to these forums and to the coding world so be nice. :o
using c++ here, ive got to draw a grid 9x9 and place a star in the middle. I can draw the grid, but the bloody star keeps appearing at the bottom, heres my code, thx for the help.


-----

#include <iostream.h>

void main ()
{
int column=0;
int row=0;
int x=5;
int y=5;

for (column=0; column <9;column ++)
{int column=0;
for (row=0; row <19; row ++)
cout <<"-"; cout << endl;
for (row=0; row <10; row++)
cout << "| ";
cout << endl;}
for (row=0; row <19; row ++)
cout <<"-"; cout << endl;

for (int row=0; row <19; ++row)
{cout <<endl;
for (int column=0; column <10; ++column)
if ((column==x)&&(row==y))
cout <<"?";
else
cout <<"*";
}
return;
}

Unit
04-26-2004, 07:50 PM
That is happening because you already drew the grid. There are two ways to deal with this.

- print the asterisk while you are making the grid. start drawing the grid and when you detect that you are at the middle of the grid, draw the asterisk and continue with the grid.

- print the asterisk by using console gotoxy functions.

the first method is very portable in the sense that you can even redirect the output the printer and the asterisk would still be in the middle of the grid.

btw, your code is very confusing..

for example

for (column=0; column <9;column ++)
{int column=0;

It is a very bad programming practice to use overlapping scopes for variables. besides you are not even using that variable inside the loop!

Try to implement my first suggestion. You will need to go with the second method if you are writing something interactive like a game.

Spookster
04-26-2004, 09:42 PM
^ This looks very much like a homework assignment. Professors like to give this type of problem out as homework.

wargis,

In the future you need to read our posting guidelines regarding proper titles of threads.

Unit
04-26-2004, 09:44 PM
That's the reason I tried to point him in the right direction and not feed him with full blown code ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum