1. ## Digit Check

I need some help with checking whether or not the input from the user is 5 digits or not. It needs to be exactly 5 digits and for example 00000 should be a valid input so I can just check if it is between 10000 and 99999. My brain is just not working right now and I need help.

2. That helps but how do i use that to check if it is exactly 5 digits. my input has to be all at once and not one at a time.

Thank you btw for the help it was a good help

3. I would get the number as a string then convert to your number after checking length.

If you are using std::string then check std::string.length(), for a cstring use strlen() to check the length.

Jim

4. Thank you so much

I just have one more question. once i convert the string to an int will i lose my leading zeros and if i do how do i prevent that? for example if the user types in 00000, which should be a valid in put and i convert it to an int won't it display as just 0? I need it to display as 00000

I read some where that there is a %9 method for checking but i did not understand what they were doing. It was just code that I was reading....would some thing along those lines work?

5. It depends on what you are actually doing. Do you really need to convert to a number? Or can you stick with the string?

A little code would probably help.

Jim

6. for the program to work i do not need to use an int i can stick with a string. the numbers represent a bank account number but the instructions say to use an int. in fact it even says the program should take it in as an int

7. Ok, since the instructions say take it as in int then that's the way you should do it. If using an int it shouldn't matter if the number entered is 100 or 000100. The only thing you should worry about is if the number is too big.

Jim

8. how do i make it display as 5 digits and make sure that it is 5 digits if it is an int?

9. When you display it you can use a combination of std::setw() and std::setfill().

Jim

10. ok that solves part of my problem but if the user types in 100 that is not valid but if her types in 00100 it is valid how do i check for that as an int? it seems like I;m checking for key strokes...

11. You don't need to check the length of the int you need to check the value. Even if you enter 00001 to an int what gets stored is 1.

the numbers represent a bank account number but the instructions say to use an int. in fact it even says the program should take it in as an int
Your instructions do say to use an int?

If you are using it as an int as your instructions state then don't worry about he length, unless your instructions say something different.

Jim

12. Yeah my instructor said that he's checking for the length most of all like if he puts in 1234 he does not want it to be valid but if her puts in 01234 he wants it to be valid.

he also wants us to tell him if the user didn't put enough digits or too many
But to my understanding if those are both in an int they would be stored as the same thing....

13. Then you must use a string to get the data from the user.

Jim

14. Thank you. You have been really helpful