This is my code: it works,but when the user answers correctly until question 7,the question 8, 9 , 10 will be skipped and goes to result instantly,can someone tell me whats wrong?i been looking it trhough for hours >.< thanks
void hangman (void)
{
int wrong =0;
int answer;
char back;
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
//Question 1
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
}
printf("Question 1\n");
printf("What is the Atomic number of Potassium?\n");
scanf("%d", &answer);
if (answer != 19)
{wrong++;}
//Question 2
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
}
printf("Question 2\n");
printf("What is the Atomic number of Hydrogen?\n");
scanf("%d", &answer);
if (answer != 1)
{wrong++;}
//Question 3
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
}
printf("Question 3\n");
printf("What is the electron number of sodium?\n");
scanf("%d", &answer);
if (answer != 11)
{wrong++;}
//Question 4
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 3 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
}
printf("Question 4\n");
printf("What is the group number of silver?\n");
scanf("%d", &answer);
if (answer != 11)
{wrong++;}
//Question 5
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 3 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 4 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
}
printf("Question 5\n");
printf("What is the neutron number of chlorine?\n");
scanf("%d", &answer);
if (answer != 18)
{wrong++;}
//Question 6
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 3 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 4 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 5 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
}
printf("Question 6\n");
printf("What is the period number of sodium?\n");
scanf("%d", &answer);
if (answer != 3)
{wrong++;}
//Question 7
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 3 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 4 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 5 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
case 6 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | /\n");
printf("__|_________\n\n");
break;
}
printf("Question 7\n");
printf("What is the group number of oxygen?\n");
scanf("%d", &answer);
if (answer != 16)
{wrong++;}
//Question 8
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
printf("Question 8\n");
printf("What is the proton number of Rubidium?\n");
scanf("%d", &answer);
if (answer != 37)
{wrong++;}
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 8\n");
printf("What is the proton number of Rubidium?\n");
scanf("%d", &answer);
if (answer != 37)
{wrong++;}
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 8\n");
printf("What is the proton number of Rubidium?\n");
scanf("%d", &answer);
if (answer != 37)
{wrong++;}
case 3 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 8\n");
printf("What is the proton number of Rubidium?\n");
scanf("%d", &answer);
if (answer != 37)
{wrong++;}
case 4 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 8\n");
printf("What is the proton number of Rubidium?\n");
scanf("%d", &answer);
if (answer != 37)
{wrong++;}
case 5 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 8\n");
printf("What is the proton number of Rubidium?\n");
scanf("%d", &answer);
if (answer != 37)
{wrong++;}
case 6 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | /\n");
printf("__|_________\n\n");
printf("Question 8\n");
printf("What is the proton number of Rubidium?\n");
scanf("%d", &answer);
if (answer != 37)
{wrong++;}
break;
case 7 :
break;
}
//Question 9
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
printf("Question 9\n");
printf("What is the group number of calcium?\n");
scanf("%d", &answer);
if (answer != 2)
{wrong++;}
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 9\n");
printf("What is the group number of calcium?\n");
scanf("%d", &answer);
if (answer != 2)
{wrong++;}
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 9\n");
printf("What is the group number of calcium?\n");
scanf("%d", &answer);
if (answer != 2)
{wrong++;}
case 3 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 9\n");
printf("What is the group number of calcium?\n");
scanf("%d", &answer);
if (answer != 2)
{ wrong++;}
case 4 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 9\n");
printf("What is the group number of calcium?\n");
scanf("%d", &answer);
if (answer != 2)
{wrong++;}
case 5 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 9\n");
printf("What is the group number of calcium?\n");
scanf("%d", &answer);
if (answer != 2)
{wrong++;}
case 6 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | /\n");
printf("__|_________\n\n");
break;
printf("Question 9\n");
printf("What is the group number of calcium?\n");
scanf("%d", &answer);
if (answer != 2)
{wrong++;}
case 7 :
break;
case 8 :
break;
}
//Question 10
system ("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Answer as many question correctly as possible or the man will be hanged!!\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
break;
printf("Question 10\n");
printf("What is the proton number of carbon?\n");
scanf("%d", &answer);
if (answer != 6)
{wrong++;}
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 10\n");
printf("What is the proton number of carbon?\n");
scanf("%d", &answer);
if (answer != 6)
{wrong++;}
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 10\n");
printf("What is the proton number of carbon?\n");
scanf("%d", &answer);
if (answer != 6)
{wrong++;}
case 3 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 10\n");
printf("What is the proton number of carbon?\n");
scanf("%d", &answer);
if (answer != 6)
{wrong++;}
case 4 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 10\n");
printf("What is the proton number of carbon?\n");
scanf("%d", &answer);
if (answer != 6)
{wrong++;}
case 5 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
break;
printf("Question 10\n");
printf("What is the proton number of carbon?\n");
scanf("%d", &answer);
if (answer != 6)
{wrong++;}
case 6 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | /\n");
printf("__|_________\n\n");
break;
printf("Question 10\n");
printf("What is the proton number of carbon?\n");
scanf("%d", &answer);
if (answer != 6)
{wrong++;}
case 7 :
break;
case 8 :
break;
case 9 :
break;
}
system("cls");
printf("\t**********************************************************************\n");
printf("\t* Welcome to try Hangman optional games! *\n");
printf("\t**********************************************************************\n\n\n");
printf("Result:\n\n");
switch (wrong) {
case 0 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("____________\n\n");
printf("CONGRATULATIONS, THE MAN SURVIVE!");
break;
case 1 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
printf("CONGRATULATIONS, THE MAN SURVIVE!");
break;
case 2 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" |\n");
printf(" |\n");
printf(" |\n");
printf("__|_________\n\n");
printf("CONGRATULATIONS, THE MAN SURVIVE!");
break;
case 3 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | |\n");
printf(" | |\n");
printf(" |\n");
printf("__|_________\n\n");
printf("CONGRATULATIONS, THE MAN SURVIVE!");
break;
case 4 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
printf("CONGRATULATIONS, THE MAN SURVIVE!");
break;
case 5 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" |\n");
printf("__|_________\n\n");
printf("CONGRATULATIONS, THE MAN SURVIVE!");
break;
case 6 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | /\n");
printf("__|_________\n\n");
printf("CONGRATULATIONS, THE MAN SURVIVE!");
break;
case 7 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | / \\\n");
printf("__|_________\n\n");
printf("GMAE OVER");
break;
case 8 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | / \\\n");
printf("__|_________\n\n");
printf("GMAE OVER");
break;
case 9 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | / \\\n");
printf("__|_________\n\n");
printf("GMAE OVER");
break;
case 10 :
printf("Amount of wrong answers: %d\n\n", wrong);
printf(" _______\n");
printf(" |/ | \n");
printf(" | O \n");
printf(" | \\|/\n");
printf(" | | \n");
printf(" | / \\\n");
printf("__|_________\n\n");
printf("GMAE OVER");
break;
}
printf("\n\nWould you like to go back to main menu? y/n\n");
scanf(" %c", &back);
if (back == 'y')
{system ("cls");
main ();}
else if (back == 'Y')
{system ("cls");
main ();}
else
return 0;
}