Program that displays odd, even, and reversed digits

Hello,
I'm currently trying to make a program that validates user input and displays the digits in the number as odd and even, and also displays the number reversed. In addition to these things, there has to be a space between the digits of the number. I'm a C++ beginner and I am having a lot of problems. I've searched everywhere but I'm unable to fix these issues.

I'm only able to use the following topics in order to write the code which are:
• Increment and decrement operators
• The while loop
• Do-while loop
• For loop
• Nested loop

It should read as:
Enter a number:
54321
Original number: 54321
Number reversed: 1 2 3 4 5
Even digits: 4 2
Odd digits: 5 3 1

The issues I'm currently having are:
1. If the user enters a number that is a special character or a letter it has to validate the input.

2. The program is not recognizing that each digit is it's own number, so the even calculation only works if I input a single digit such as 6, and the odd calculation is not working.

3. I'm not sure how to put a space between each digit or reverse the number.

If anyone is able to help with any of these things I'd really appreciate it!

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
using namespace std;

int main()
{
									
	int digits = 0;
	int even = 0;
	int odd = 0;
	int reversed = 0;
	int remainder;
	char ch;


	do
	{

		cout << "Enter an integer and press <ENTER>" << endl;
		cin >> digits;

		cout << "The original number is " << digits << endl;
		cout << "The number reversed is " << reversed << endl;

	

		if ((digits % 2) == 0) {
			even = even + digits++;

			cout << "The even digits are " << even << endl;
		
		}
		else
			cout << "There are no even digits" << endl;

		{


			if ((digits % 2) != 0) {
				odd = odd + digits++;
				cout << "The odd digits are " << odd << endl;

			}
			else
				cout << "There are no odd digits" << endl;
			{

			}

			


		}

	

			cout << "y/Y to continue, anything else to exit" << endl; 

			cin.clear();
			cin >> ch;

			

		} while ((ch == 'y') || (ch == 'Y')); 



		//system("pause");
		return 0;

	}

Last edited on
The program is not recognizing that each digit is it's own number,

Then you have to separate the input into digits.

In a base-N number system you do get the least significant digit with input % N
You can remove the least significant digit with input = input / N

The above operations in a loop can iterate all digits of a number.
Thank you, is it possible you can show an example of how to implement that into the code?
I'm currently trying to make a program that validates user input and displays the digits in the number as odd and even, and also displays the number reversed. In addition to these things, there has to be a space between the digits of the number. I'm a C++ beginner and I am having a lot of problems. I've searched everywhere but I'm unable to fix these issues.
I'm only able to use the following topics in order to write the code which are:
• Increment and decrement operators
• The while loop
• Do-while loop
• For loop
• Nested loop
It should read as:
Enter a number:
54321
Original number: 54321
Number reversed: 1 2 3 4 5
Even digits: 4 2
Odd digits: 5 3 1
The issues I'm currently having are:
1. If the user enters a number that is a special character or a letter it has to validate the input.
2. The program is not recognizing that each digit is it's own number, so the even calculation only works if I input a single digit such as 6, and the odd calculation is not working.
3. I'm not sure how to put a space between each digit or reverse the number.
is it possible you can show an example of how to implement that into the code?

Have you read here?
http://www.cplusplus.com/forum/beginner/1/
admin wrote:
Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.

If this is an assignment, IMHO you’ve already received good hints.
If it’s not an assignment, please clearly state it.
Topic archived. No new replies allowed.