Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Why wont this work? External drive with HFS partition and NTFS partition? techmonkey OS X 10 Feb 13, 2009 10:42 AM
Why wont this file work on my ATV? MacBoobsPro Apple TV and Home Theater 17 Jun 12, 2008 01:49 PM
Why wont this play??? skythefly13 iPhone 11 Jul 12, 2007 11:29 AM
Why wont this Ram stick work? Josh2022 Mac Basics and Help 18 Sep 11, 2005 10:20 AM
why wont this web page save as PDF in Firefox? inlimbo Mac Applications and Mac App Store 3 Jun 28, 2005 10:02 AM


All times are GMT -5. The time now is 03:55 PM.

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

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