in c++ is it possible to have a maximum length of an input, say i am entering a number - is it possible just enforce a rule which says that only a 2 number integer can be entered? i.e 01, 02, 03, 10 20, 30
dello 0 Light Poster
Recommended Answers
Jump to PostThe simplest way is to do it in a do ... while() loop like this:
// Dev C++ #include <cstdlib> #include <iostream> using namespace std; int main() { int n; // keeps looping until a number < 100 is entered do { cout << "Enter an integer …
Jump to PostSo I guess you will have to user a parser to deal with it,
We can do this :
1) Take the number into a string,
2) Check if it has only digits in it, use
All 7 Replies
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
kangarooblood -4 Light Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
kangarooblood -4 Light Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
kangarooblood -4 Light Poster
Sky Diploma 571 Practically a Posting Shark
Ancient Dragon commented: Good approach :) +36
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.