Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 21, 2011, 10:39 PM   #1
DaKyd55
macrumors member
 
Join Date: Jul 2010
eep why wont this work

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 kainjow; Apr 22, 2011 at 02:08 AM. Reason: code tags
DaKyd55 is offline   0 Reply With Quote
Old Apr 21, 2011, 11:02 PM   #2
Ganesha
macrumors member
 
Join Date: Aug 2009
Quote:
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.
Ganesha is offline   0 Reply With Quote
Old Apr 22, 2011, 02:11 AM   #3
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
For this chunk of code you can just reuse std::cin to read in the next input.
kainjow is offline   0 Reply With Quote
Old Apr 22, 2011, 07:29 AM   #4
DaKyd55
Thread Starter
macrumors member
 
Join Date: Jul 2010
so its the getch thats not working because theres no conio.h right? so what would i use in xcode instead of getch
DaKyd55 is offline   0 Reply With Quote
Old Apr 22, 2011, 10:09 AM   #5
Ganesha
macrumors member
 
Join Date: Aug 2009
Quote:
Originally Posted by DaKyd55 View Post
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.
Ganesha is offline   0 Reply With Quote
Old Apr 22, 2011, 07:34 PM   #6
DaKyd55
Thread Starter
macrumors member
 
Join Date: Jul 2010
Quote:
Originally Posted by Ganesha View Post
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
DaKyd55 is offline   0 Reply With Quote
Old Apr 23, 2011, 12:05 PM   #7
Ganesha
macrumors member
 
Join Date: Aug 2009
Quote:
Originally Posted by DaKyd55 View Post
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.
Ganesha is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPhone: App Wont Work After JB adminaaah Jailbreaks and iOS Hacks 0 Mar 9, 2014 09:48 AM
It wont work!!! wornout iPhone Tips, Help and Troubleshooting 5 Feb 21, 2014 11:48 AM
New Apple TV wont work on Samsung TV jamesco Apple TV and Home Theater 93 Dec 7, 2013 07:11 PM
iPhone: 6.1.3 Exploit Wont Work idenRen Jailbreaks and iOS Hacks 6 Jul 16, 2013 05:26 PM
My MacBook Keyboard wont work! iDarX MacBook 2 Jul 3, 2012 04:25 PM

Forum Jump

All times are GMT -5. The time now is 09:41 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC