Using Getch()

Discussion in 'C Programming' started by Hollow06, Jul 4, 2007.

  1. Hollow06

    Hollow06

    Joined:
    Jul 4, 2007
    Messages:
    2
    I'm learning C++ dummies book to learn C++. I am using bloodshed(latest version as my compiler...although it sux with headers bigtime and never seems to want to work. But I am confortable with it...anyhooo. Here is the dilly-0.

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <conio.h>
    #include <sstream>
    #include <istream>// in stream
    #include <iomanip>
    #include <stdlib.h> // I've included all these to try and fix wtv the prob.
    
    //This function catches  what numbers are being typed and allows up until the enter key "/r" is pressed.
    
    string EnterOnlyNumbers() {  // A function to make sure only Numbers 
           string numAsString = ""; // are entered.
           char ch = getch();
           while (ch != '/r') {   [U]//warning! -> Multi-character character constant[/U]
                 if (ch >= '0' && ch <= '9') { /
                        cout << ch;
                        numAsString += ch;
                 }
                 ch = getch();
           }
           return numAsString;
    }
    Any ideas or a simpliar way let me know. I'm try to get the basics down so if you want to throw out Your way...that might help. Other wise post back what is wrong. This code is right OUT OF THE BOOK "C++ for Dummies".
     
    Hollow06, Jul 4, 2007
    #1
    1. Advertising

  2. Hollow06

    Hollow06

    Joined:
    Jul 4, 2007
    Messages:
    2
    Got it

    wrong slash.....
     
    Hollow06, Jul 4, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. azsx

    getch in Java

    azsx, May 3, 2006, in forum: Java
    Replies:
    5
    Views:
    9,473
  2. Matthew
    Replies:
    0
    Views:
    2,907
    Matthew
    Jun 28, 2003
  3. voidstar
    Replies:
    3
    Views:
    10,100
    Mark R Rivet
    Jul 27, 2004
  4. Shugong Wang
    Replies:
    2
    Views:
    9,624
    Raymond Martineau
    Nov 28, 2004
  5. aurgathor
    Replies:
    4
    Views:
    7,939
    Karl Heinz Buchegger
    Mar 16, 2005
Loading...

Share This Page