My first Program: tell me what you think [Archive] - C Board

PDA

View Full Version : My first Program: tell me what you think


roberth9000
09-12-2002, 09:05 PM
this is a game of tic-tac-toe that i made it was my firstr attemt at writing a c++ program please tell me what you think

black
09-12-2002, 09:56 PM
I'd like to try your game but dunno its rules...:( maybe I need a readme. :o

Hammer
09-13-2002, 03:35 AM
- goto statements
Don't use them. They're OK in special cases, but in a program of this size, they're not needed.

- toe variable
You can tidy your declaration of this variable like so:
>toe[]={'1','2','3','4', etc

- cout << "\033[2J";
That didn't work properly on my system. There must be a safer equivalent.

- cout<<toe[6]<<" | "<<toe[7]<<" | "<<toe[8]<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
Maybe a loop would look better?


if (toe[0]==b && toe[1]==b && toe[2]==b)
w=1;
if (toe[3]==b && toe[4]==b && toe[5]==b)
w=1;
Use "else if", that way once a match is found, the rest of the if stataments will be bypassed. This is a small and pointless efficiency change in a program of this size, but still good to know for future development.

All in all, I've seen a lot worse tic-tac-toe programs, so it's a good start :)

biosninja
09-13-2002, 04:07 AM
It's cool.:)

The keys is your numpad keys... That figured out

try to put the keys on the screen before you play the game

possible bug : if you choose the 1'st block, it gives a strange character.

roberth9000
09-13-2002, 02:53 PM
You can tidy your declaration of this variable like so:
>toe[]={'1','2','3','4', etc
i tred this but i got these too erors back
error C2059: syntax error : ']'
error C2001: newline in constant
toe[]={'1','2','3','4,'5','6','7','8','9'};
can you tell me what i did wrong

thanks biosninja i fixed what you found about the first square

black: i am making in a in game help sequence that will tell you how to play i will post an updated version a soon as i get my erors fixxed

Hammer
09-13-2002, 04:13 PM
Initliasing the toe variable...

#include <stdio.h>

int main(void)
{
char toe[] = {'1','2','3','4','5','6','7','8','9'};
int i;

for (i = 0; i < sizeof (toe); i++)
printf ("%c\n", toe[i]);

return 0;
}
or

#include <stdio.h>

int main(void)
{
char toe[9];
int i;
for (i = 0; i < sizeof (toe); i++)
toe[i] = (char)(i + 1 + '0');

for (i = 0; i < sizeof (toe); i++)
printf ("%c\n", toe[i]);

return 0;
}

Alphabird32
09-13-2002, 07:43 PM
I don't know why I'm crying. It just makes me happy when a newbie posts his game(didn't download it). I just wish atleast 50% of the world population would be programmers and not casual gamers who think graphics rule......

TechWins
09-14-2002, 12:03 AM
wtf are you talking about?