Thread: Need some help

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    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;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Tags for this Thread