|
-
September 23rd, 2002, 08:33 PM
#1
user input datatype check?
hey hey.. can anyone answer this simple question for me?
i have a program that prompts the user to input a number. I then want to check to make sure the user inputs a number and not a character of some kind yet I am unsure of how to do this.
Could someone tell me what i need to do?
I tried the following.
double Distance;
cout << "Enter distance: ";
cin >> Distance;
while(!Distance || Distance < 0)
{
cout << "Error";
cout << "Enter distance: ";
cin >> Distance;
}
the following code works if i enter a negative number.. it will keep prompting me to enter the distance again. But if i type a letter or any other character i get an error at !Distance
any help would be appreciated
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|