Hi all
I've been asked to write a C++ program that the user enters a five digit integer.
The program then needs to return how many zeros in the number, how many odd numbers and how many even numbers.
I've set it up to %2=0 and %2!=0 to determine if the number is odd or even.
I don't know how to separate the odds and evens.
Any help would be great.
Thanks
Ian
Ian Woodgate 0 Newbie Poster
Recommended Answers
Jump to PostYou can set up a while loop which will iterate 5 times.
Each time you will extract the last digit by: d=n%10 ,now you can check whether it is 0 or odd or even and then divide the number by 10(n=n/10) which will remove the last digit so each time …
Jump to PostYour program looks nice but your use of boost library is probably not allowed in his program. It's like hitting a nail with a sludge hammer, way too overkill.
Jump to Postmain(nargs, args) // I haven't seen this MAIN signature since int nargs; // 1985! AFAIK, this has been deprecated char **args; // for over 30 years {
Would you believe some people still write code in that style? I've seen in recently (10 years or so) …
All 12 Replies
profyou 13 Newbie Poster
Ancient Dragon commented: good answer :) +14
ModernC++ 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
ModernC++ commented: If I don't use at least one function/class from boost (at least STL) in 50 lines of code I may explode +0
ModernC++ 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
phani1092 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Ian Woodgate 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
profyou 13 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.