Posted 6 years ago
·
Author
so i have this huge ass project and the problem is that when i input a char just to check it
the program sort of crashes crashes. (it just prints nonestop)
(it may be something little i didnt see but im quite "blind" to those things
i will never see the problem unless someone points it out)
to point it out . the functions within the 'switch case/break' are completely fine
the program sort of crashes crashes. (it just prints nonestop)
(it may be something little i didnt see but im quite "blind" to those things
i will never see the problem unless someone points it out)
to point it out . the functions within the 'switch case/break' are completely fine
/**this function gets a choice and calls to the functions who do the rest of the game
input : choice , answer
output : none , when you lose or win it asks you if you wanna play again **/
void levelChoice(void)
{
int choice = 0;
enum Level
{
easy = 1,
medium,
hard,
crazy
};
scanf("%d", &choice);
if ((choice < ONE)||(choice < ZERO)||(choice > SIX)) /* i know the default is supposed to do
this job but as you see when i input a char its still crashes. */
{
printf("look .. i dont know whats wrong with you but i am not dumb so please look up the rules again and enter a LEGAL answer. thank you . \n");
do
{
getsecretpassword();
Welcome();
levelChoice();
} while (YES == answer);
fflush(stdin);
if (NO != answer)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
else
{
printf("@ @ oh well B Y E B Y E :(( @ @ \n");
}
}
else
{
switch (choice)
{
case easy :
rounds = EROUNDS;
while (ZERO != rounds)
{
inputEasy();
fc = hits();
checkingIfRight();
printf("! ! you have %d rounds left ! !\n", rounds);
}
fflush(stdin);
if (ZERO == rounds)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
fflush(stdin);
if (NO != answer)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
else
{
printf("@ @ oh well B Y E B Y E :(( @ @ \n");
}
break;
case medium :
rounds = MROUNDS;
while (ZERO != rounds)
{
inputMedium();
fc = hits();
checkingIfRight();
printf("! ! you have %d rounds left ! !\n", rounds);
}
if (ZERO == rounds)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
fflush(stdin);
if (NO != answer)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
else
{
printf("@ @ oh well B Y E B Y E :(( @ @ \n");
}
break;
case hard :
rounds = HROUNDS;
while (ZERO != rounds)
{
inputHard();
fc = hits();
checkingIfRight();
}
fflush(stdin);
if (ZERO == rounds)
{
printf("# # wanna play again?? y for yes and n for no. # #");
scanf("%c", &answer);
}
if (NO != answer)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
else
{
printf("@ @ oh well B Y E B Y E :(( @ @ \n");
}
break;
case crazy :
srand(time(NULL));
int Crounds = (rand() % 21) + 5;
rounds = Crounds;
while (ZERO != rounds)
{
printf("$ $ C R A Z Y M O D E $ $ \n\n");
inputCrazy();
fc = hits();
checkingIfRight();
}
if (ZERO == rounds)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
fflush(stdin);
if (NO != answer)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
else
{
printf("@ @ oh well B Y E B Y E :(( @ @ \n");
}
break;
default :
printf("look .. i dont know whats wrong with you but i am not dumb so please look up the rules again and enter a LEGAL answer. thank you . \n");
do
{
getsecretpassword();
Welcome();
levelChoice();
} while (YES == answer);
fflush(stdin);
if (NO != answer)
{
printf("# # wanna play again?? y for yes and n for no. # # \n");
scanf("%c", &answer);
}
else
{
printf("@ @ oh well B Y E B Y E :(( @ @ \n");
}
break;
}
}
}