Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Project: Concentration
- Description: The concentration game generates random numbers and displays them for short period of time for the user to memorize.
- During the time the random numbers are displayed, the player tries to memorize the number and their sequence.
- After a few seconds have passed, the computer screen is cleared and the user is asked to input the same numbers in the same sequence.
- */
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- // Declarations
- char cYesNo = 'z';
- int guessNum1 = 0;
- int guessNum2 = 0, guessNum3 = 0;
- int randNuml = 0, randNum2 = 0, randNum3 = 0;
- int elapsedTime = 0;
- int currentTime = 0;
- int counter = 0;
- srand(time(NULL));
- // Input, Process, Output
- printf("Play a game of Concentration? (y or n): ");
- scanf("%c", &cYesNo);
- if(cYesNo == 'y' cYesNo == 'Y')
- {
- randNuml = rand() % 100;
- randNum2 = rand() % 100;
- randNum3 = rand() % 100;
- printf("\nConcentrate on the next three numbers\n");
- printf("\n\t%d %d %d\n\n", randNuml , randNum2, randNum3);
- currentTime = time(NULL);
- do{
- elapsedTime = time(NULL);
- }while ((elapsedTime - currentTime) < 3);
- system("cls");
- printf("\nEnter each # separated with one space: ");
- scanf("%d%d%d", &guessNum1, &guessNum2, &guessNum3);
- if(randNuml == guessNum1 && randNum2 == guessNum2 && randNum3 == guessNum3)
- printf("\nCongratulations!\n");
- else
- printf("\nSorry, correct numbers were: %d %d %d\n", randNuml, randNum2, randNum3);
- }
- printf("\nPress any key to quit");
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement