I entered the scrap newline loop after the user enters the 3 answers, but sometimes the "Would you like..." appears only once on the first iteration, but then runs through twice after selecting a new game??
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int scrap = 0;
int iNum1 = 0;
int iNum2 = 0;
int iNum3 = 0;
int iAns1 = 0;
int iAns2 = 0;
int iAns3 = 0;
int iCurrentTime = 0;
int iElapsedTime = 0;
char YesOrNo = '\0';
//char YesOrNo[2];
srand((unsigned)time(NULL));
do {
printf("\n\t***********************************\n");
printf("\t* A GAME OF CONCENTRATION *\n");
printf("\t***********************************\n");
printf("\n\tWould you like to play a game ('Y' or 'N') ?: ");
scanf("%c", &YesOrNo);
//fgets(YesOrNo, 2, stdin);
while (scrap != '\n') scrap = getchar();
if (YesOrNo == 'y' || YesOrNo == 'Y'){//if1
iNum1 = ((unsigned)rand()) %100 + 1;
iNum2 = ((unsigned)rand()) %100 + 1;
iNum3 = ((unsigned)rand()) %100 + 1;
printf("Watch the 3 numbers closely.\n");
printf("\n\n%d %d %d\n", iNum1, iNum2, iNum3);
fflush(stdout);
iCurrentTime = ((unsigned)time(NULL));
do{
iElapsedTime = ((unsigned)time(NULL));
}while((iElapsedTime - iCurrentTime) <2);
system("cls");
//for(x=0;x<100;x++){
// printf("\n");
//}
printf("Enter the 3 numbers with a space in between: \n");
scanf("%d %d %d", &iAns1, &iAns2, &iAns3);
while(scrap != '\n') scrap = getchar();
if (iAns1 == iNum1 && iAns2 == iNum2 && iAns3 == iNum3){//if2
printf("\n\n\t\tCONGRATULATIONS!\n");
}//if2
else{ //else2
printf("\nSorry, the correct answers were %d %d %d\n", iNum1, iNum2, iNum3);
}//else2
}//if1
else if (YesOrNo == 'n' || YesOrNo == 'n'){
printf("\nGOODBYE\n");
break;
}
}while(1);
return 0;
}//main