Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Programming some game

Name: Anonymous 2007-03-16 11:30 ID:+Cao99ew

Okay.. i'm a noob at C and i'm trying to do some game.
It's a game for 2 players. The first player inputs 4 numbers. The 2nd player tries to guess which numbers those are by inputting numbers too. If there is a correct number in wrong order, 0 will print. If there is a correct number in correct order, 1 will print. Game will end if the 2nd player gets 1111 or uses up all 10 turns.

I can't understand the array stuff much.. help me.

Name: Anonymous 2007-03-16 12:56 ID:RRc9gyTb

Well, let me explain. An array is a way to store severable variables of the same type in one structure. For example, if we wanted to create a structure called "test" containing ints, we'll declare:

int test[X]; //X is the number of variables you want in your array

So if I declare:
 
int array[4];

array contains 4 ints

To store something, you do:

array[X]=4; //where X is where you want to store data

The first term of an array is always 0. So if you want to have an array of 4 ints containing numbers 1, 2, 3 and 4, you'll do:

int array[4];
array[0]=1;
array[1]=2;
array[2]=3;
array[3]=4;

You access your array the same way than you write in it; for example:

printf("First term of arrat is %i", array[0]);

For your game, you could use two arrays, one for the numbers entered by player 1, and one for numbers enter by player 2. Then you would compare the values of the arrays as follows:

int i;
for(i=0;i<4;i++)
{
  if player1[i]==player2[i]
    puts("1");
  else
    puts("0");
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List