Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DaKyd55

macrumors member
Original poster
Jul 3, 2010
81
0
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;
}
 
Last edited by a moderator:
For this chunk of code you can just reuse std::cin to read in the next input.
 
so its the getch thats not working because theres no conio.h right? so what would i use in xcode instead of getch
 
good point. but for future reference how would i get it to detect a key

This question can get pretty complex depending on how you want to do it. Google "Non-blocking user input without ncurses" for tips.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.