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-18 7:31 ID:1sFWNjzO

>>70
>>55 again.
Ok, here is the input function, try to do the rest, I'll post the full code later :
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define MAX_LENGTH 6

void player_input(char player[], const int n);
const int player_1 = 1;
const int player_2 = 2;

int main(void)
{
  char player1[MAX_LENGTH] = {0};
  char player2[MAX_LENGTH] = {0};
  int i;
 
  player_input(player1, player_1);
  player_input(player2, player_2);
 
  for (i = 0; i < MAX_LENGTH - 2; i++)
    if (player1[i] == player2[i])
      puts("1");
    else
      puts("0");
  puts("THIS CODE WAS MADE BY ZE GREAT KILLER OF POUSSIN, ENJOY YOUR AIDS, HA!"); 
  return EXIT_SUCCESS;
}

void player_input(char player[], const int n)
{
  int i;
 
  printf("player %d : enter numbers or GTFO\n", n);
  fgets(player, MAX_LENGTH, stdin);
  for (i = 0; i < MAX_LENGTH - 2; i++)
    if (!isdigit(player[i]))
      {
    puts("bad input, try again moron");
    player_input(player, n);
      }
}

Make the ask_player() function, with a #define MAX_TRIES 10 and  an int that will be compared to this value, while its inferior, ask the player, if it's 'y' or 'Y' return to the beginning of the program, else, exit. It's easy, 10 lines or code or something like that.

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