Using Getch()

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

  1. Hollow06

    Hollow06

    Joined:
    Jul 4, 2007
    Messages:
    2
    Likes Received:
    0
    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 (Text):

    #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. Advertisements

  2. Hollow06

    Hollow06

    Joined:
    Jul 4, 2007
    Messages:
    2
    Likes Received:
    0
    Got it

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

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:
    10,494
  2. Matthew
    Replies:
    0
    Views:
    3,098
    Matthew
    Jun 28, 2003
  3. voidstar
    Replies:
    3
    Views:
    10,553
    Mark R Rivet
    Jul 27, 2004
  4. Shugong Wang
    Replies:
    2
    Views:
    9,868
    Raymond Martineau
    Nov 28, 2004
  5. aurgathor
    Replies:
    4
    Views:
    8,347
    Karl Heinz Buchegger
    Mar 16, 2005
  6. lior l

    getch() in c

    lior l, Aug 13, 2003, in forum: C Programming
    Replies:
    5
    Views:
    26,542
    Programming Guru
    Oct 5, 2011
  7. Jozsa Boti

    getch() in Python

    Jozsa Boti, Sep 16, 2003, in forum: Python
    Replies:
    1
    Views:
    2,058
    Muthukumaraswamy
    Dec 28, 2012
  8. Ron Adam

    IDLE and msvcrt getch()

    Ron Adam, Oct 26, 2003, in forum: Python
    Replies:
    0
    Views:
    1,086
    Ron Adam
    Oct 26, 2003
Loading...