Classify Numbers Again?

This code was given to me by swejnc, but with some modifications 'cause I'm trying to display every number the user inputs (to which I haven't figured how to do so as of yet). For instance, when asked, "How many intergers do you want to classify?" The user puts 5, so he/she will begin typing 5 intergers: 1, 2, 3, 4, 5.

The odd, even, and zero will analyze and kick in displaying:

Odd: 3
Even: 2
Zero: 0

However, what I'm trying to do or what I would like to ask is, what or how can I display the numbers the user inputted? You know, showing 1 thru 5 when displayed in printResult.

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
#include <iostream>

void getNumber(int &num);
void analyzeNumber(int &num, int &evenSize, int &oddSize, int &zeroSize);
void printResults(int num, int evenSize, int oddSize, int zeroSize);
int main()//int argc, char** argv)
{
	int num_size, numOfEven = 0, numOfOdd = 0, numOfZero = 0, num;

	std::cout << "How many intergers do you want to classify? ";
	std::cin >> num_size;

	for (int repeat = 0; repeat < num_size; repeat++)
	{
        getNumber(num);
		analyzeNumber(num, numOfEven, numOfOdd, numOfZero);
	}

	printResults(num, numOfEven, numOfOdd, numOfZero);

    system("pause");
    
	return 0;
}

void getNumber(int number)
{

	std::cout << "\nEnter an interger number: ";

	std::cin >> number;
	//return number;
}


void analyzeNumber(int &num, int &evenSize, int &oddSize, int &zeroSize)
{
	if(num!=0)
	{
		if((num%2) ==0)
			evenSize++;
		else
			oddSize++;
	}
	else
	{
		zeroSize++;
	}
}

void printResults(int num, int evenSize, int oddSize, int zeroSize)
{
    std::cout << "The numbers typed: " << num << "\n";
    
	std::cout << "Number of even: " << evenSize << std::endl;

	std::cout << "Number of odd: " << oddSize << std::endl;

	std::cout << "Number of zero: " << zeroSize << std::endl;
}
Last edited on
You'll have to store the numbers in an array or a vector which you then pass to printResults(). You'll have to add a loop in printResults to print out all the values.
Topic archived. No new replies allowed.