Code Assistance

This assignment I have been working on has been stumping me, I even refused to turn what i have in just because I want to understand. The premise is this:

"Write a program that asks the user to enter a series of one-digit non-negative numbers (you will need todo error checking).
When the user has finished entering number (Note: the user should indicate that they are finished by entering the value 10), print out how many of each number the user entered.
There must be three functions including main.
The main function will read in the values from the user and do validity checking on the input.
If the number is in the range 0 to 9 main will call a second function that will count the number.
After all of the numbers have been entered the main function will call a third function to display the results.
You must not use global variables."

Here is what I have so far

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
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "Lab10_Exercise2.h"
#include <iostream>
#include <string>

using namespace std;

int storenumber ( int [], const int, int, int, int, int, int, int, int, int, int, int, int );
void countduplicatenumbers (int, int, int, int, int, int, int, int, int, int);

int main()
{
	const int SIZE = 100;
	int onedigitnum[SIZE];
	int count = 0;
	int number;
	int Zero = 0, One = 0, Two = 0, Three = 0, Four = 0, Five = 0, Six = 0, Seven = 0, Eight = 0, Nine = 0;

	cout << "Enter a one-digit number or 10 to exit: ";
	cin >> number;

	while ( number != 10 && count < SIZE)
	{
		
		if ( number >= 0 && number <= 9 )
		{
			count++;
			onedigitnum[count - 1] = number;
			storenumber ( onedigitnum, SIZE, count, Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine );
			cout << "Enter a one-digit number or 10 to exit: ";
			cin >> number;
		}
		else
		{
			cout << "You've entered in an in valid number." << endl;
			
			cout << "Enter a one-digit number or 10 to exit: ";
			cin >> number;
		}
	
	}

	countduplicatenumbers ( Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine);
	cout << endl << endl;
	return 0;
}

int storenumber ( int usernumber[], const int size, int count, int countZero, int countOne, int countTwo, int countThree, int countFour, int countFive, int countSix, int countSeven, int countEight, int countNine)
{

	for (int index = 0; index <= count; index++)
	{
		if ( usernumber[index] == 0)
		{
			++countZero;
		}
		else if ( usernumber[index] == 1)
		{
			++countOne;
		}
		else if ( usernumber[index] == 2)
		{
			++countTwo;
		}
		else if ( usernumber[index] == 3)
		{
			++countThree;
		}
		else if ( usernumber[index] == 4)
		{
			++countFour;
		}
		else if ( usernumber[index] == 5)
		{
			++countFive;
		}
		else if ( usernumber[index] == 6)
		{
			++countSix;
		}
		else if ( usernumber[index] == 7)
		{
			++countSeven;
		}
		else if ( usernumber[index] == 8)
		{
			++countEight;
		}
		else if ( usernumber[index] == 9)
		{
			++countNine;
		}
	
		return countZero, countOne, countTwo, countThree, countFour, countFive, countSix, countSeven, countEight, countNine;
	
	}

}

void countduplicatenumbers (int Zero, int One, int Two, int Three, int Four, int Five, int Six, int Seven, int Eight, int Nine)
{
	cout << "You've entered " << Zero << " 0 (s)" << endl;
	cout << "You've entered " << One << " 1 (s)" << endl;
	cout << "You've entered " << Two << " 2 (s)" << endl;
	cout << "You've entered " << Three << " 3 (s)" << endl;
	cout << "You've entered " << Four << " 4 (s)" << endl;
	cout << "You've entered " << Five << " 5 (s)" << endl;
	cout << "You've entered " << Six << " 6 (s)" << endl;
	cout << "You've entered " << Seven << " 7 (s)" << endl;
	cout << "You've entered " << Eight << " 8 (s)" << endl;
	cout << "You've entered " << Nine << " 9 (s)" << endl;

}


Now I have run this code, what i want for it to do is taking the values that are returned from the second function, to display them in the third function. So if I enter three 1's, seven 2's, etc the cout will display them. Is there something I'm missing? Any hints or tips would be appreciated.
Last edited on
What is missing is your function to display the results. Hint: You have collected your counts in your array onedigititem..
Ok I see I have collected my counts into my array. So what I need to do is in the 3rd function is to when it is called is to utilize my counts in the array to display my results correct?
That's how I would do it.
Alright I have done a bit of editing however I'm still having the issue with my cout in the third function:

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "Lab10_Exercise2.h"
#include <iostream>
#include <string>

using namespace std;

int storenumber ( int [], const int, int, int [], int );
void countduplicatenumbers (int [], int );

int main()
{
	const int SIZE = 100;
	const int num = 10;
	int onedigitnum[SIZE];
	int onedigit[num];
	onedigit[0] = 0;
	onedigit[1] = 0;
	onedigit[2] = 0;
	onedigit[3] = 0;
	onedigit[4] = 0;
	onedigit[5] = 0;
	onedigit[7] = 0;
	onedigit[8] = 0;
	onedigit[9] = 0;
	
	int count = 0;
	int number;

	cout << "Enter a one-digit number or 10 to exit: ";
	cin >> number;

	while ( number != 10 && count < SIZE)
	{
		
		if ( number >= 0 && number <= 9 )
		{
			count++;
			onedigitnum[count - 1] = number;
			storenumber ( onedigitnum, SIZE, count, onedigit, num );
			cout << "Enter a one-digit number or 10 to exit: ";
			cin >> number;
		}
		else
		{
			cout << "Enter in a valid number." << endl;
			
			cout << "Enter a one-digit number or 10 to exit: ";
			cin >> number;
		}
	
	}

	countduplicatenumbers ( onedigit, num );
	cout << endl << endl;
	return 0;
}

int storenumber ( int usernumber[], const int size, int count, int digit [], int sizetwo )
{

	for (int index = 0; index <= count; index++)
	{
		if ( usernumber[index] == 0)
		{
			++digit[0];
		}
		else if ( usernumber[index] == 1)
		{
			++digit[1];
		}
		else if ( usernumber[index] == 2)
		{
			++digit[2];
		}
		else if ( usernumber[index] == 3)
		{
			++digit[3];
		}
		else if ( usernumber[index] == 4)
		{
			++digit[4];
		}
		else if ( usernumber[index] == 5)
		{
			++digit[5];
		}
		else if ( usernumber[index] == 6)
		{
			++digit[6];
		}
		else if ( usernumber[index] == 7)
		{
			++digit[7];
		}
		else if ( usernumber[index] == 8)
		{
			++digit[8];
		}
		else if ( usernumber[index] == 9)
		{
			++digit[9];
		}

		return digit[0], digit [1], digit [2], digit [3], digit [4], digit [5], digit [6], digit [7], digit [8], digit [9];
	
	}

}

void countduplicatenumbers (int onedigitnumber[],int count)
{
	cout << "\nYou've entered " << onedigitnumber [0] << " 0 (s)" << endl;
	cout << "You've entered " << onedigitnumber [1] << " 1 (s)" << endl;
	cout << "You've entered " << onedigitnumber [2] << " 2 (s)" << endl;
	cout << "You've entered " << onedigitnumber [3] << " 3 (s)" << endl;
	cout << "You've entered " << onedigitnumber [4] << " 4 (s)" << endl;
	cout << "You've entered " << onedigitnumber [5] << " 5 (s)" << endl;
	cout << "You've entered " << onedigitnumber [6] << " 6 (s)" << endl;
	cout << "You've entered " << onedigitnumber [7] << " 7 (s)" << endl;
	cout << "You've entered " << onedigitnumber [8] << " 8 (s)" << endl;
	cout << "You've entered " << onedigitnumber [9] << " 9 (s)" << endl;

}


What seems to happen depending on the last value entered it accumulates the total number into that array, and then 6 is always -858993460, any help appreciated!
Last edited on
Alright found out why [6] was acting weird, the other issue still persists.
This doesn't address your issue, but your storenumber() function is designed to return an integer, not several integer arrays! But, you are not using the return value for anything, so you might as well make the function a void function instead of int.

What other issue remains?
Topic archived. No new replies allowed.