3 function Array Please help

Write a program that asks the user to enter a series of one-digit non-negative numbers (you will need to do 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.

#include <iostream>

using namespace std;

void valCounter(int[]);
void displayVal(int[],int);



int main()
{
int input;
int num[10] = {0};
cout<<"please enter a number between 1 and 9, or ten to exit"<<endl;
cin>>input;
while(input<0 || input<10)
{
cout<<"The following was an invalid entry, please try agian"<<endl;
cin>>input;
}
valCounter[input];

}

void valCounter(int[10], int)
{


That is what I have so far, but I am really confused on what to do next. I am not sure how to set up the array, or the the function is correct. Help is appreciated.
Last edited on
Note: Any help is appreciated, and I need to finish this before tomorrow night.
int main()
{
int input;
int num[10] = {0};
cout<<"please enter a number between 1 and 9, or ten to exit"<<endl;
cin>>input;
if(input<0 ||input>10)
{
cout<<"invalid entry, please try again"<<endl;
cin>>input;
}
while (input !=10)
{
valCounter(num, 10);

cout << "enter a single didgit number between 0-9 enter 10 to exit" << endl;
cin >> input;
if(input<0 ||input>10)
{
cout<<"invalid entry, please try again"<<endl;
cin>>input;
}
}

displayVal(num, 10);

system("pause");
return 0;

}

void valCounter(int num[10], int input)
{

num[input]++;
}

void displayVal(int num[10],int size)
{
for ( int i = 0; i < size; i++)
{
if ( num[i] != 0)
{
cout << "you entered " <<num[i]<< ", " << i << "(s)" << endl;
}
}
}

What I have now, but it still doesn't work
Hi randomperson27,

In order to get the code compiled you need either prototype your functions or declare them before main function.

Inside the function displayVal you made a little mistake, you changed the order of the variables:

cout << "you entered " <<num[ i ]<< ", " << num[ i ] << "(s)" << endl;

In your main function you could simplify your 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
int main()
{
    int input = 0;
    int num[10] = {0};

    cout << "please enter a number between 0 and 9, or 10 to exit" << endl;

    while (input != 10)
    {
        cin >> input;
        if (input < 0 || input > 10)
        {
            cout << "invalid entry, please try again" << endl;
            continue;
        }
        else if (input != 10)
        {
            valCounter (num, input);
            cout << "please enter a number between 1 and 9, or ten to exit" << endl;
        }
    }

    displayVal(num, 10);

    return 0;

}


and please rearrange your code so that it becomes readable.
Topic archived. No new replies allowed.