How can my program recieve exactly 8 digit input??

Hey guys..what can i do if i want my program to take 8 digit input number ,no less no more than it.. i try to ask my frind but its hard to get..
(but not using getche()8x)

so example i have to input number ID..and if i input just 2 digit or more than 8 digit it shouldn't response or said that the input is not valid..
Last edited on
The last post there will guarantee only a full integer is accepted from user (no garbage chars)
http://www.cplusplus.com/forum/beginner/13044/#msg62827

As for keeping it 8 digits you can make a simple test
1
2
3
4
5
cin n;
if(n > 99999999 || n < 10000000)
{
  //handle bad input
}
Last edited on
@soranz.. you made lots of mistake.
n>99999999 it's eight times nine..it should be seven times..
n<10000000 it's one followed by 7 zeros.. it should be 8 zeros.
and you used || between two condition that will accept all input greater that eight times nine(as you write but actual one should have to seven times nine)..
Last edited on
thaks guys..it's really help me..
HiteshhVaghani1:
@soranz.. you made lots of mistake.
n>99999999 it's eight times nine..it should be seven times..
n<10000000 it's one followed by 7 zeros.. it should be 8 zeros.
and you used || between two condition that will accept all input greater that eight times nine(as you write but actual one should have to seven times nine)..


Last time I checked Neo frost wanted 8 digits, and 99999999 is the largest number you can have with only 8 digits (excluding decimals) and 1000000 is the smallest number you can have with 8 digits (including decimals).
So as a conclusion: No you are wrong and soranz was right, when trying to correct someone choose one who isn't smarter than you.
Thanks Latrakx :)

We all make mistakes ~
Well, there are numbers and there are numbers. For example a serial number or an account number etc. could have some leading zeros. In the general case the entire number could consist of zeros. The only thing we know is that each position contains a digit (0-9) and there are eight of them.

That makes the full range 00000000 to 99999999.

It may be necessary or useful to treat the input as a character string, rather than an integer.
Last edited on
You're right Chervil.
OP should be more clear so we don't have to guess what he means by 'number' ;)
Topic archived. No new replies allowed.