PDA

View Full Version : eep why wont this work




DaKyd55
Apr 21, 2011, 10:39 PM
so simple but non-working

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

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



Ganesha
Apr 21, 2011, 11:02 PM
its the getch that wont work. is it different than on windows? why wont this **** work??

conio.h does not exist on UNIX and Linux systems.

kainjow
Apr 22, 2011, 02:11 AM
For this chunk of code you can just reuse std::cin to read in the next input.

DaKyd55
Apr 22, 2011, 07:29 AM
so its the getch thats not working because theres no conio.h right? so what would i use in xcode instead of getch

Ganesha
Apr 22, 2011, 10:09 AM
so its the getch thats not working because theres no conio.h right? so what would i use in xcode instead of getch

Like kainjow said just use std::cin again, with a new variable.

DaKyd55
Apr 22, 2011, 07:34 PM
Like kainjow said just use std::cin again, with a new variable.

good point. but for future reference how would i get it to detect a key

Ganesha
Apr 23, 2011, 12:05 PM
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.