Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char cYesNo = '\0';
int option = 0;
int game = 0;
int iResp1 = 0;
int iResp2 = 0;
int iResp3 = 0;
int iResp4 = 0;
int iResp5 = 0;
int iElaspedTime = 0;
int iCurrentTime = 0;
int iRandomNum = 0;
int i1 = 0;
int i2 = 0;
int i3 = 0;
int i4 = 0;
int i5 = 0;
int iCounter = 0;
srand(time(NULL));
system("cls");
printf("\n\t\tThank you for playing the concentration game!\n");
do
{
printf("\n\t1\tEasy - Remember 3 numbers in 5 seconds");
printf("\n\t2\tIntermediate - Remember 5 numbers in 5 seconds");
printf("\n\t3\tDifficult - Remember 5 numbers in 2 seconds");
printf("\n\t4\tQUIT");
printf("\n\n\tPlease choose difficulty (1 or 4): ");
scanf("%d", &option);
switch (option)
{
case 1:
{
i1 = rand() % 100;
i2 = rand() % 100;
i3 = rand() % 100;
printf("\n\n\tConcentrate on the next three numbers\n");
printf("\n\t%d\t%d\t%d\n", i1, i2, i3);
iCurrentTime = time(NULL);
do
{
iElaspedTime = time(NULL);
} while( (iElaspedTime - iCurrentTime) < 5 ); //end do while loop
system("cls");
printf("\n\tEnter each # seperated with one space: ");
scanf("%d%d%d", &iResp1, &iResp2, &iResp3);
if( i1==iResp1 && i2==iResp2 && i3==iResp3 )
printf("\n\tCongratulations!\n\n");
else
printf("\n\tSorry, correct numbers were %d %d %d\n", i1, i2, i3);
printf("\tPlay again (y or n)? ");
scanf("%c", &cYesNo);
if( cYesNo == 'n' || cYesNo == 'N' )
game = 1;
break;
}
case 2:
{
i1 = rand() % 100;
i2 = rand() % 100;
i3 = rand() % 100;
i4 = rand() % 100;
i5 = rand() % 100;
printf("\n\n\tConcentrate on the next three numbers\n");
printf("\n\t%d\t%d\t%d\t%d\t%d\n", i1, i2, i3, i4, i5);
iCurrentTime = time(NULL);
do
{
iElaspedTime = time(NULL);
} while( (iElaspedTime - iCurrentTime) < 5 ); //end do while loop
system("cls");
printf("\n\tEnter each # seperated with one space: ");
scanf("%d%d%d%d%d", &iResp1, &iResp2, &iResp3, &iResp4, &iResp5);
if( i1==iResp1 && i2==iResp2 && i3==iResp3 && i4==iResp4 && i5==iResp5 )
printf("\n\tCongratulations!\n\n");
else
printf("\n\tSorry, correct numbers were %d %d %d %d %d\n", i1, i2, i3, i4, i5);
printf("\tPlay again (y or n)? ");
scanf("%c", &cYesNo);
if( cYesNo == 'n' || cYesNo == 'N' )
game = 1;
break;
}
case 3:
{
i1 = rand() % 100;
i2 = rand() % 100;
i3 = rand() % 100;
i4 = rand() % 100;
i5 = rand() % 100;
printf("\n\n\tConcentrate on the next three numbers\n");
printf("\n\t%d\t%d\t%d\t%d\t%d\n", i1, i2, i3, i4, i5);
iCurrentTime = time(NULL);
do
{
iElaspedTime = time(NULL);
} while( (iElaspedTime - iCurrentTime) < 2 ); //end do while loop
system("cls");
printf("\n\tEnter each # seperated with one space: ");
scanf("%d%d%d%d%d", &iResp1, &iResp2, &iResp3, &iResp4, &iResp5);
if( i1==iResp1 && i2==iResp2 && i3==iResp3 && i4==iResp4 && i5==iResp5 )
printf("\n\tCongratulations!\n\n");
else
printf("\n\tSorry, correct numbers were %d %d %d %d %d\n", i1, i2, i3, i4, i5);
printf("\tPlay again (y or n)? ");
scanf("%c", &cYesNo);
if( cYesNo == 'n' || cYesNo == 'N' )
game = 1;
break;
}
case 4:
{
printf("\n\t\tBye bye!\n");
game = 1;
break;
}
} // end switch
} while (!game);
return 0;
} // end function