Giants745 Posted October 13, 2014 Share Posted October 13, 2014 For some odd reason I can not think how to do this correctly The prompt is: Design and Implement an application that determines and prints the number of odd,even,and zero digits in an integer value read from the keyboard. The main twist is, I can't use Strings. Any help on this would be amazing! Quote Link to comment Share on other sites More sharing options...
blue :D Posted October 14, 2014 Share Posted October 14, 2014 (edited) input a number if number < 0: // Base case, if it is less than 0 you can't really count the digits, and it should be an integer anyway return zerocount, evencount, oddcount or however you want to implement it if number % 10 == 0: // This means that the number ends with a 0, zerocount++ recursively call function (number / 10) // To get to the next digit else if number % 2 == 1: // This means the number ends with a 1,3,5,7,9 oddcount++ recursively call (number / 10) else: // Number is even evencount++ recursively call (number / 10) I'm not sure I quickly read over it and just wrote this up quickly, if you have any other questions I'll gladly help if I can Edited October 14, 2014 by blue :D Quote Link to comment Share on other sites More sharing options...
DeRedPanda Posted October 14, 2014 Share Posted October 14, 2014 For future help, as much as we would all like to think, we are not all genius coders. This website is extremely helpful and most of the time your questions get answered. http://stackoverflow.com Quote Link to comment Share on other sites More sharing options...
Giants745 Posted October 14, 2014 Author Share Posted October 14, 2014 Thank you very much Quote Link to comment Share on other sites More sharing options...
-O-P-rime Posted October 14, 2014 Share Posted October 14, 2014 i would have just created a custom vector class to store input variables as Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.