Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 6th, 2006, 11:57 AM   #1
n00b
Programmer
 
Join Date: Sep 2005
Posts: 69
Rep Power: 4 n00b is on a distinguished road
Send a message via MSN to n00b
input control

if i write the code like...
int number;
	cout << "Enter a number: "; cin >> number;
	while(!cin)
	{
		cin.clear();
		cin.ignore(100,'\n');
		cout << "Enter a NUMBER: " << endl;
		cin >> number;
	};
...to make sure the user inputs digits only, it works fine. but if i have a variable of "char" type, it wont wont print the warning if i enter digits instead of characters. how do i solve this?
n00b is offline   Reply With Quote
Old Nov 6th, 2006, 12:51 PM   #2
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>but if i have a variable of "char" type, it wont wont print the warning if i enter digits instead of characters.
That's because all user input is character based. Even if you type a digit, it's still the character representation of that digit.

>how do i solve this?
You have to manually validate each character using one of the functions in <cctype> or read everything as a string and parse using one of several common methods.
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old Nov 6th, 2006, 2:52 PM   #3
n00b
Programmer
 
Join Date: Sep 2005
Posts: 69
Rep Power: 4 n00b is on a distinguished road
Send a message via MSN to n00b
rgr that, the last solution will do
n00b is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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
Reading character input into an array (raw mode) shoeyfighter C 3 Nov 2nd, 2006 4:49 PM
questions on windows sendMessage and RichEdit control nomer C++ 1 Mar 3rd, 2006 3:51 AM
User input jayme C++ 38 Nov 25th, 2005 8:27 PM
C programing control of the Serial Port. Light C++ 5 Feb 24th, 2005 3:14 PM
Show web user control hidden see07 C# 1 Feb 2nd, 2005 11:35 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:30 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC