Ok, I have two problems. first of all, every other scanf is ignored. and second, of all it ends up displaying:
To play Simple Simon, watch the screen for a sequence of digits.
Watch carefully, as the digits are only displayed for a second!
The computer will remove them, and then prompt you to enter the same sequence.
When you do, you must put spaces in between the digits.
Good luck!
Press enter to play
7 8
Now enter your sequence - don't forget the spaces
7 8
Wrong!
Your score is 0
Do you want to play agan (y/n)?
Ok... well its suppost to have the numbers BELOW the enter your sequence and its suppost to display them for a second and than have them disappear... and theres suppost to be three digits to start with... but it only outputs 2... but instead it waits a second and than outputs everything after the first 78... everythings EXACTLY how it is in the book so I don't know whats wrong =P (My only guess is that its an old book)
Also, it stops at do you want to play agan... and ignores the scanf... heres the code...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
int main(void)
{
char another_game = 'Y';
char correct = TRUE;
int counter = 0;
int sequence_length = 0;
int i = 0;
long seed = 0;
int number = 0;
long now = 0;
long time_taken = 0;
printf("\nTo play Simple Simon, ");
printf("watch the screen for a sequence of digits.");
printf("\nWatch carefully, as the digits are only displayed for a second!");
printf("\nThe computer will remove them, and then prompt you");
printf(" to enter the same sequence.");
printf("\nWhen you do, you must put spaces in between the digits. \n");
printf("\nGood luck!\nPress enter to play\n");
scanf("%c", &another_game);
do
{
correct = TRUE;
counter = 0;
sequence_length = 2;
time_taken = clock();
while(correct)
{
sequence_length += counter++%3 == 0;
seed = time(NULL);
now = clock();
srand((int)seed);
for(i = 1 ; i <= sequence_length ; i++)
printf("%d ", rand() % 10);
printf("\r");
for(i = 1; i <= sequence_length; i++);
printf(" ");
if(counter == 1)
printf("\nNow enter your sequence - don't forget the spaces\n");
else
printf("\r");
srand((int)seed);
for(i = 1 ; i <= sequence_length ; i++)
{
scanf("%d", &number);
if(number != rand() % 10)
{
correct = FALSE;
break;
}
}
printf("%s\n", correct ? "Correct!" : "Wrong!");
}
time_taken = (clock() - time_taken) / CLOCKS_PER_SEC;
printf("\n\n Your score is %d", --counter * 100 / time_taken);
fflush(stdin);
fflush(stdout);
printf("\nDo you want to play agan (y/n)? ");
scanf("%c", &another_game);
} while(another_game == 'y' || another_game == 'Y');
}