0

I dont get why my switch for the gameover screen wont work properly. Everytime i go to the gameOverByQ it just flashes it and goes back to choiceLocation really fast. How do I maintain the gameOverByQ screen?

void gameOverByQ(char \*nInput)
{

    system("cls");
    printf("                 GAME OVER!                 \n\t");
    printf("Aww really???? We havent even started yet :(\n\t");
    printf ("\n");
    printf ("\n");
    printf ("\n\t");
    printf ("[P]lay again?             [E]xit Game\n\t");
    printf("Your Choice: ");
    scanf("%c", nInput);
        if (*nInput=='P')
            printf("play again");
        else if (*nInput=='E')
            exit(0);
}

int choiceLocation (char nInput)
{
int onHand = 0;
int day =1;
int gil =20000;
int debt = 50000;
do
{
system("cls");
printf ("Gilgamesh: Where should my travels take me to?");
printf ("\\n");
printf ("\\n\\t");
printf ("\[1\] Tycoon Meteor's Minerals                       Day #%d\\n\\t",day);
printf ("\[2\] Pulsian Restoratives                           Gil: %d\\n\\t", gil);
printf ("\[3\] Archadian Luxuries                             Debt: %d\\n\\t", debt);
printf ("\[4\] Cid's Magical Escapades\\n\\t");
printf ("\[5\] Gaian Gratitudes                               \[Q\]uit\\n\\t");
printf ("\[6\] Riches and Minerals of Spira\\n\\t");
printf ("\[7\] Go see the Merchant of the Rift\\n\\t");
printf ("\\n");
printf ("Your choice: ");
scanf ("%c", &nInput);
switch (nInput)
{
case '1' : tycoonMM(&onHand, &day, &gil, &debt); break;
case '2' : printf ("Boring?!:(\\n"); break; //Placeholder
case '3': printf ("Boring?!:(\\n)"); break;//Placeholder
case '4' : printf ("Boring?!:(\\n)"); break;//Placeholder
case '5' : printf ("Boring?!:(\\n)"); break;//Placeholder
case '6' : printf ("Boring?!:(\\n)"); break;//Placeholder
case '7' : printf ("Boring?!:(\\n)"); break;//Placeholder
case 'Q' : gameOverByQ(&nInput); break;
}
}while (nInput \<1 || nInput\>7);   
}

I expected that the switch would be enough to take me to the gameover screen, however instead of taking me there it just fashes it really quickly and goes back to choice location.

  • 1
    Most likely, you're suffering from [`scanf()` leaves the newline character in the buffer](https://stackoverflow.com/q/5240789/15168). Use `" %c"` instead of `"%c"` in your `scanf()` statements (note the leading space). – Jonathan Leffler Nov 25 '22 at 19:45

0 Answers0