Could anyone advice me on why my loop gives a funny output?
My program should work this way...
1. Prompt user if they want to play the game
2. If user type 'y'
>>>2.1. Display 3 random number
>>>2.2. Prompt user if they want to play again.
>>>2.3. If user type 'y' again (repeat step 2.1 & 2.3)
>>>2.4. Else If user type 'n', program terminate.
3. Else if user type 'n', no loop just terminate program.
Here is my code...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void welcome_msg(void)
{
printf("Pick your number! \n");
}
void reply_msg(char reply)
{
printf("Would you like to play? (y/n) ");
scanf("%c", &reply);
}
void num_display(void)
{
srand((unsigned)time(NULL));
printf("\nNum: %i %i %i ", rand() %10, rand() %10, rand() %10);
}
void goodbye_msg(void)
{
printf("Thank you for playing.\n");
}
int main(void)
{
char answer;
welcome_msg();
reply_msg(answer);
looping: /* a label */
printf("Play again? \n ");
scanf("%c", &answer);
if(answer == 'n')
{
goodbye_msg();
}
else
{
num_display();
goto looping; /* Jump to the label*/
}
return 0;
}
Really appreciate for all the help.
Thanks in advance!