Sequence Guessing Game

This is a discussion on Sequence Guessing Game within the C Programming forums, part of the General Programming Boards category; I am having trouble with a guessing game assignment. We are to create a game where the player guesses the ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    2

    Sequence Guessing Game

    I am having trouble with a guessing game assignment. We are to create a game where the player guesses the correct sequence of 5 numbers (1-5). The game compares the sequence entered by the player to the randomly generated sequence of numbers stored in a single dimensional array. My problem is how to compare the entered numbers to the generated numbers. Here is what I have so far:
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    #define SIZE 5
    
    
    int main(){
     int index;
     int array[SIZE];
    
    printf("Game: Who's Next? \n");
    printf("Objective: Identify the Sequence of 5 numbers between 1 and 5 using the fewest \n");
    printf("turns. If you wish to quit guessing and give up, enter a ZERO for one of your \n");
    printf("guesses and the game will display the solution and quit. \n");
    printf("GOOD LUCK!\n");
    
    
         srand(time(NULL));
    
         for(index=0;index<SIZE;index++){
    
           array[index] = rand() % 5 + 1;
    }
    
    printf("Game Number Sequence \n");
    printf("--------------------- \n");
    printf("| %d | %d | %d | %d | %d | \n",array[0],array[1],array[2],array[3],array[4]);
     printf("--------------------- \n");
    
    
    return 0;
    }
    I just can't figure out what to put in the middle of the body to get the comparison

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Are you trying to get them to input a series of five numbers, and then to compare them against the five you've already made?
    Code:
    if first == generated first and
    if second == generated second ...
    ...
    if fifth == generated fifth then
        yay
    else
        boo
    Or, you could just store those five in an array, and use a loop.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    2
    The answer to your question is yes and I know to use scanf for the player's input, but how do I compare one array to another? using the "if" loop? That would seem too long, wouldn't it?

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Show an example of playing the game.

    Your description has not suggested any reasonable way of winning this game, or of even playing it well.

    For instance, if the player gets one digit right, out of the five, do you tell the player he got that one digit correct? Do you tell him which number was right out of the five digits? What if the one digit is correct, but it's in the wrong column of the goal's answer? Do you tell the user about that?

    The British have a game like this called "Cows and Bulls", but there's a lot of subtlety involved in what they report back to you, after your guess. Is this that game?

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    35
    Quote Originally Posted by Vynnos View Post
    The answer to your question is yes and I know to use scanf for the player's input, but how do I compare one array to another? using the "if" loop? That would seem too long, wouldn't it?
    it would be longish but not that long at all. and it would be fairly obvious that you are making a comparison so it would make the code more readable IMO

    have you learnt how to make functions? cause that would reduce it to one line and make the code even clearer

  6. #6
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    If you put the input into an array, you can easily compare the sequence of random numbers to it by using a for loop with an if statement inside of it, testing equality for a single element every iteration.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 10:26 AM
  2. Help!!! Number guessing game
    By JesterJoker89 in forum C++ Programming
    Replies: 16
    Last Post: 10-05-2007, 01:47 PM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 01:48 AM
  4. Random guessing game
    By Nalif in forum C Programming
    Replies: 16
    Last Post: 10-26-2006, 04:05 AM
  5. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21