C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 19th, 2005, 01:19 AM
andrew_aj1 andrew_aj1 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 andrew_aj1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 50 sec
Reputation Power: 0
Input validation

i have written many programs in c++ (some for school, and some just for fun). The problem that i have always had is that if i input a value that i did not account for my screen will get flooded with text. im looking for a way to check input for the wrong type of data.

ex: look at this problem

void main()
{
int Choice;

cin >> Choice;

switch(Choice)
{
case 1: // code here for if they pick 1
break;
case 2: // code here for if they pick 2
break;
default: // code here for if they dont pick 1 or 2
break;
}
}

this code works great if you enter any int value, but if you enter a character you get unexpected results. im looking for a simple code that will check what kind of data type was entered to see if its the kind of data i was looking for. if it is what im looking for i want it to continue, if not i want to enter the data again and again until its of the correct data type. please dont say something like look at this built in function as a reply. please tell me your ideas and some code that i may be able to use.

Thank You,

Andrew

Reply With Quote
  #2  
Old April 19th, 2005, 02:31 AM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 1 m 43 sec
Reputation Power: 4
input the value as a string, then convert it to an integer using atoi().... this will simply ignore any character values it comes across...
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Input validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway