Hello Jack Van Stone,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
At the moment what I am seeing is the while loop inside the for loop. At some point "d" will become non zero and the while loop will become an endless loop with no way out.
If I understand this correctly given the number "1234" there are two odd numbers, 1 and 3, with a sum of 4 and a count of 2 and two even numbers with a sum of 6 and a count of 2.
The more I think on it I come to the conclusion that the while loop is not needed just the for loop. When I took out the while it worked fine.
Now when the program starts my console window opens and I am left with a blank screen and a flashing cursor having no idea what to do. A prompt of what to enter would be nice.
A couple of new lines would keep the out from all running together. This may be just my personal choice.
I changed the error message to
cout << "ERROR: PLEASE RE-ENTER a number " << (num > 999999 ? " < 999999" : ">99") << ": ";
if you would like to use it.
One last point:
It is best not to use "system" anything in a program as this could leave the program vulnerable to attack by hackers who can use this. Also it tends to be specific to Windows and not everyone can use it. If it is your own program and only you will be using it that is OK, but do not let it out to everyone. An alternative you can use is:
1 2 3 4 5
|
// This next line may not be needed. If you have to press enter twice put a comment on the line.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
// Sometimes it is needed.
std::cout << "\n\n Press Enter to continue";
std::cin.get();
|
Hope that helps,
Andy