Thread: _getch()Help

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

    Post _getch()Help

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    void quit()
    {
    	char q;
    	
    	_cprintf("Are you sure you want to quit? (y/n)");
    	q = _getch();
    	
    	do
    	{
    		switch (q)
    		{
    			case 'y':
    				puts("You quit!");
    				break;
    				
    			case 'n':
    				puts("You don't quit.");
    				break;
    				
    			default: 
    				break;
    		}
    	}while((q != 'y') || (q != 'n'));
    }
    
    int main()
    {
    	quit();
    	return 0;
    }
    In the code above I'm trying to make the "quit()" function only return when you hit either the 'y' or 'n' keys. So can someone help here and tell me where I'm going wrong?

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    If selection is not 'y' or 'n', _getch() again.
    Another turbo C user???

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    2
    Okay thanks it works now, I really should've thought of that... But no I mainly use MinGW or Open Watcom, so I'm trying to make a rogue-like game that compiles with both.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting _getch() inputted numbers
    By bengreenwood in forum C++ Programming
    Replies: 9
    Last Post: 07-16-2008, 10:46 PM
  2. _getch() and doing a carriage return
    By Leeman_s in forum C++ Programming
    Replies: 7
    Last Post: 10-01-2001, 02:19 PM