You don't need more
pointers, you just need them in the right places
Let's list what you are supposed to do:
- Generate 10 random integers and save them into an array. Let's call this array random_numbers.
- Print the elements of random_numbers to the screen.
- Ask the user for a number. Let's call this number x.
- Count how many times the value of x matches an element in random_numbers.
- Print the number of times the value of x matches an element in random_numbers.
- Allow the user to run the above again without having to re-run the program.
If I were you, I would divide most these tasks into functions, and if these functions are too complex, I would further divide them into helper functions that do one thing and do it well. So, I might declare:
Code:
void generate_random_numbers(int random_numbers[], size_t n);
void print_random_numbers(const int random_numbers[], size_t n);
int get_user_input(void);
int count_matching_numbers(const int random_numbers[], size_t n, int x);
Notice that three of these functions have a pointer parameter named random_numbers. You can declare the random_numbers array in the main function as having 10 elements, then pass this array as well as the numbers of elements (n) to these functions.
With the help of count_matching_numbers, printing the number of times the value of x matches an element in random_numbers is easy: you just make use of the return value and print it in the main function.
Do all these first and make sure that it works for a single run of the program. Once you are certain it works, modify the main function to add a loop to allow the user to run the above again.