eep why wont this work

Discussion in 'Mac Programming' started by DaKyd55, Apr 21, 2011.

  1. DaKyd55, Apr 21, 2011
    Last edited by a moderator: Apr 22, 2011

    macrumors member

    Joined:
    Jul 3, 2010
    #1
    so simple but non-working

    its the getch that wont work. is it different than on windows? why wont this **** work??

    Code:
    #include <iostream>
    
    int main (int argc, char * const argv[]) {
        // insert code here...
    	int x; 
        std::cout << "Enter a Number To be Converted to feet or inches.";
    	std::cin >> x;
    	std::cout << "Ok. Now type 1 for inches2feet or 2 for feet2inches.";
    	if(_getch()=='1')
    	{
    		std::cout << x*12;
    	}
    	if(_getch()=='2')
    	{
    		std::cout << x/12;
    	}
        return 0;
    }
     
  2. macrumors regular

    Joined:
    Aug 4, 2009
    #2
    conio.h does not exist on UNIX and Linux systems.
     
  3. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    For this chunk of code you can just reuse std::cin to read in the next input.
     
  4. thread starter macrumors member

    Joined:
    Jul 3, 2010
    #4
    so its the getch thats not working because theres no conio.h right? so what would i use in xcode instead of getch
     
  5. macrumors regular

    Joined:
    Aug 4, 2009
    #5
    Like kainjow said just use std::cin again, with a new variable.
     
  6. thread starter macrumors member

    Joined:
    Jul 3, 2010
    #6
    good point. but for future reference how would i get it to detect a key
     
  7. macrumors regular

    Joined:
    Aug 4, 2009
    #7
    This question can get pretty complex depending on how you want to do it. Google "Non-blocking user input without ncurses" for tips.
     

Share This Page