HELP: Program for counting Even, Odd, Zero digits in an input.

Hey all.

So, I'm relatively new to C++, and I have to write a program that will take an input and count the even, odd, and zero digits from the input number.
Problem is, I got it to count the evens and odds, but no matter what I do it won't seem to count my zero digits; simply outputs the number of even digits, number of odd digits, and a 0 for the zero digits even if there are zero digits present in the input.

This is what I have at the moment after rewriting it many times:

Mind you, this is incomplete so it doesn't look very good, but I'm just looking to get the main function working properly before I fix it up and what-not.

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
  #include <iomanip>
#include <iostream>
#include <cstdlib>
#include <cmath>


using namespace std;

int main()
{
	


//Local Constants
int QUIT = 0;

//Local Variables
int Odd_Count = 0;
int Even_Count = 0;
int Zero_Count = 0;
int num;
int digit;
/***************************start main program************************/

cout << "Enter a number: " << endl;
cin  >> num;

system ("cls");

		
	while(num != QUIT)
	{
		digit = num % 10;
		num /=10;
	
		if((digit != 0) && (digit % 2 == 0))
		{
			Even_Count++;
		}
		else if(digit == 0)
		{
			Zero_Count++;
		}
		else
		{
			Odd_Count++;
		}
	}
	
	cout << Even_Count << endl;
	cout << Odd_Count  << endl;
	cout << Zero_Count << endl;
	
	
		
	system("pause");
	system("cls");
	
	cout << "Enter another number: " << endl;
	cin  >> num;
		


return 0;
}
Note: I am aware that I need a second loop inside of the first while loop, as well as a second input-prompt to repeat the first loop, but I'm not entirely sure what the inside loop parameters should be, or how to get it to actually count zeros.
Works fine for me? Only thing I'd advise is to make int QUIT an actualy constant and to find another method besides system(). Of course, you also need to finish what you said you were going to finish.
Try this
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
#include<iostream>
using std::cout;
using std::cin;
using std::endl;


int main(){

const int QUIT=0;

int
        odd_count=0,
        even_count=0,
        zero_count=0,
        number,
        digit,
        aux;

cout<<"Enter a number (or -1 to exit): ";
cin>>number;

//SOME CLEAR SCREEN METHOD -i don't need it-

while(number!=-1){
        aux=number;
        while(aux!=QUIT){
                digit=aux%10;
                aux/=10;
                if(digit!=0 && digit%2==0){
                        even_count++;
                }else{if(digit==0)
                                zero_count++;
                        else
                                odd_count++;
                }//end if...else     
        }//end inner loop while
        if(number==0)
                zero_count++;
        cout<<"Even: "<<even_count
                <<"\nOdd:  "<<odd_count
                <<"\nZero: "<<zero_count
                <<'\n';

        zero_count=0;
        even_count=0;
        odd_count=0;

        cout<<"Enter a number (or -1 to quit): ";
        cin>>number;
}//end outer loop while

cout<<endl;
 
return 0; //indicates successful termination
}//end main 



Enter a number (or -1 to exit): 0
Even: 0
Odd:  0
Zero: 1
Enter a number (or -1 to quit): 30027
Even: 1
Odd:  2
Zero: 2
Enter a number (or -1 to quit): 1
Even: 0
Odd:  1
Zero: 0
Enter a number (or -1 to quit): 300
Even: 0
Odd:  1
Zero: 2
Enter a number (or -1 to quit): 0  
Even: 0
Odd:  0
Zero: 1
Enter a number (or -1 to quit): -1
Daleth, what compiler are you using?

I'm using Bloodshed's Dev C++ (required for the course I'm taking).

eyenrique, I'll give that a shot and let you know what happens.
So I tried your method Eyenrique, everything seemed to work, I just changed it around a bit to fit the way I like things styled and such. Thanks for the help guys, I've been trying to get this to work for almost a week now with no luck, and I still don't understand why it wouldn't count my zeros.
This is what my near-final product looks like.

Now I just need to make the output screen look all fancy and I'll be set. Thanks so much for the help guys.

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
#include<cstdlib>
#include<iomanip>
using namespace std;


int main()
{

	//local constants
	const int QUIT = 0;  //sentinel value
	
	//local variables
	int Odd_Count = 0;   //Counter for odd digits
	int Even_Count = 0;  //counter for even digits
	int Zero_Count = 0;  //counter for zero digits
	int Number;          //variable for user input
	int Digit;           //variable for each digit
	int Manip_Int;       //variable that will actually be manipulated
	
	//Prompt user for input or quit
	cout<<"Enter a number (or -1 to quit): ";
	cin >> Number;
	
	//clear the screen
	system("cls");
	
	//first while loop, determines whether or not to run the program
	while(Number != -1)
	{
	        //set the manipulatable variable equal to user input
			Manip_Int = Number;
	        
			//inner while loop, where actual math is executed
			while(Manip_Int != QUIT)
			{
	                //Mods the manip_int by 10 to isolate each digit
					Digit = Manip_Int % 10;
	                
	                //Removes the last digit from the number
					Manip_Int /= 10;
	                
	                //If digit is even
					if(Digit != 0 && Digit % 2 == 0)
					{
	                    //increment even counter
						Even_Count++;
	                }
					
					//if digit is zero
					else if(Digit == 0)
					{
	                    //increment zero counter
						Zero_Count++;
	            	}
					
					//if digit is neither even nor zero
					else
	                {
	                	 //increment odd counter
						 Odd_Count++;
	            	}
	        }     
    
    //if the users input is 0 and does not initiate the while loops
	if(Number == 0)
	{
		//increment the zero counter
		Zero_Count++;
	}
	
	//display heading to screen
	cout << "Digit Classifier \n\n\n\n";
	
	//display even count to screen	
	cout << " Even: "    << Even_Count;
	
	//display odd count to screen
	cout << "\n Odd:  " << Odd_Count;
	
	//display zero count to screen
	cout << "\n Zero: " << Zero_Count;
	
	//clear the screen
	system("cls");
	
	//reset all counters to zero
	Zero_Count = 0;
	Even_Count = 0;
	Odd_Count = 0;
	
	//Prompt user for next input or quit
	cout << "Enter a number (or -1 to quit): ";
	cin  >> Number;
	}
	
	//return 0 to the os 
	return 0;
}
it looks good!
you are welcome
good luck! @AbelX17
Topic archived. No new replies allowed.