# Thread: Sequence Guessing Game

1. ## 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. 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.

3. 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. 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. Originally Posted by Vynnos
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. 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