-
Need some help
Hi guys, I am in need of some real help for my C class. I can't seem to understand why it won't accept 'y' when I input it in. I have not finished it and is only at the beginning of the coding since I don't want to move on without dealing with this first. It's the beginning of the 21 matchstick game. I really appreciate the help.
Code:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
//void printsticks (void);
void play (void);
int main (void)
{
char answer;
printf ("Would you like to play 21 sticks? [y/n]\n");
scanf (" %c", &answer);
answer = tolower (answer);
if (answer != 'y')
printf ("You did not select yes\n");
return 0;
while (answer == 'y')
{
play();
printf ("Continue? [y/n]\n");
scanf (" %c", &answer);
}
return 0;
}
void play (void)
{
printf ("testing");
return;
}
-
Code:
if (answer != 'y')
printf ("You did not select yes\n");
return 0;
You didn't wrap those last two lines in braces, so as soon as the program hits return 0;, it ends.
Quzah.