Using Getch()

Joined
Jul 4, 2007
Messages
2
Reaction score
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:
#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".
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top