Hello Guys I'm on the hacker edition on pset1

I just wants to get the number of digits that the users type but it doesn't want to read more than 10 digits !

and when typing zero as a first digit it returns me a different value than i typed !

her is my code

notice here when I typed 12345 it gave me that i typed 5 digits My code

notice here that when i typed 123456789123456789 it gave that i typed 10 Digits only ! and another number than i typed ! My Code

hope to find an answer for that :'D thanks in advance

1 Answer 1


So, what is the allowed range that an int can have? How big a number can you stuff into an int?

Part of the problem's purpose is to figure out how to handle such a large "number". Think about what you have to do with it. Much of the work is to process the individual digits in the number. I could be wrong, but I don't believe you have to do anything with the number as a whole. While you are attempting to process it as an actual number, perhaps you should consider processing it as a string? Also, what does your code do if the first digit is a zero? If you were processing an actual number, any leading zeros would simply be ignored.

If this answers your question, please click the check mark to accept this and remove the question from the unanswered pool. Let's keep up on forum maintenance. ;-)

  • It's not about the pset itself , it just confused me how it gave me this strange numbers when typing zero at first and that it can't handle more than 10 digits and read it as 10 digits ! even GetLogLong isn't read a 16 digit !! yeah sure I will handle a digit digit , but I just wanted to add a much more functionality so if the user adds a number that is less than 16 digits it show him that he entered an invalid credit card number without making the whole process .. It could be handled as a string then convert it into integer but why to do that and make alot of process
    – A.ezzat
    Aug 15, 2015 at 19:21
  • I was trying to drop hints about what is going on. First of all, an int will not handle a 16 digit number. An int is a 4 byte signed integer variable and is limited to numbers from -2,147,483,648 to 2,147,483,647. Yes, it will handle 9 digits and some 10 digit integers, but nothing larger. You'd need to find a workaround or a data type that can handle 16 decimal digits. (continued...)
    – Cliff B
    Aug 15, 2015 at 19:37
  • Yes, a long long will handle 16 digits, but you could have an input with one or more leading zeros. Let's look at a 5 digit number instead of 16. If the number were 00234, and you tried to stroe it as an int, you would lose the first 2 digits and would only have 234. How would the code then know the difference between 00234 and 234? One is the correct length, the other is not. Next, the problem involves processing the individual digits based on position. It's a lot simpler to process the whole thing as a string, one char at a time. So yes, it is about the pset itself.
    – Cliff B
    Aug 15, 2015 at 19:41
  • Thank you Cliff , You cleared things up to me :'D
    – A.ezzat
    Aug 15, 2015 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .