### Long Integer Problem: Output Errors

Write a function that takes as a parameter an integer (as a long value) and returns the number of odd, even, and zero digits.

Here is my code. I get bad output when I put the number: 23040598763
as input.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546`` `````` #include using namespace std; void digitCount(long num); int main () { long num; cout <<"Enter a long number. " <>num; cout <

My output is:

 ``` number of zeros = 2 number of odd numbers = 6 number of even numbers = 4 ```

The odd numbers should be 5 given the number I put in, and that same output comes up no matter what long number I put in. I need this soon...
Last edited on
A long number like 23040598763 does not fit into a 32 bit integer. Try using `long long` as the variable type or testing with numbers smaller than 2^32=4294967296
Last edited on
Heh heh, yeah, that would have been smart, but there's just one problem... I'm not allowed to use `long long` for this program.
One more thing I should mention: You are working with signed integers so really you should be using numbers that are less than 2^31. Since one bit is dedicated to the sign of the number.
Last edited on
But I have to use an 11 digit number!
Does the negative sign on a 10 digit negative number count as 11 digits? If not, I am afraid you are out of luck getting an 11 digit number from a 32 bit integer.
Darn... well thanks anyway!
 I'm not allowed to use long long for this program. But I have to use an 11 digit number!

I've seen this pattern before. Every suggested solution is shot down as being forbidden. It might be better to post the full question, including any restrictions, at the start.

But having said that a couple of other thoughts come to mind. One is the use of a string, the other is the use of the double type.
Last edited on
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152`` ``````#include #include using namespace std; void digitCount(string num); int main() { string num;//="23040598763"; cout<<"Enter a long number. "<>num; cout<<"\nThe number is: "<
Topic archived. No new replies allowed.