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.
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.
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;
}
}
}
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;
}
elseif (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.