Original Post
I am having trouble sending a user defined function to another user defined function. The other tricky part to this is sending an array to another function. Here is my code..
**** Sorry for the sloppy code, I was trying to give you an idea of what I was trying to do ********
In this program, I am trying to send user input from the store_input() to the calculation(). The calculation function will then return the average which it will deliver to the show(). The show function will then display the average. I need an explanation on how I can send one function to another ? Also a quick explanation on how I should treat function arrays especially when transferring arrays to another function.
#include <iostream>
using namespace std;
const int size = 10; // Number of elements
int store_input(int [], int); // User input
int calculation(int[], int); // Calculating average
void show(int []); // Displaying data
int main()
{
int store_score[size] = {0,0,0,0,0,0,0,0,0,0}; // Store values array
store_input(store_score, size);
calculation(); // Calculating average
show(); // Displaying data
system("Pause");
return 0;
}
int store_input(int arr[], int size)
{
int send_score = 0; // Send to another function
int i;
cout << "Enter your score: " << endl;
for(int i = 0; i < size; i++)
{
cin >> arr;
send_score = send_score + arr;
}
return send_score;
}
int calculation(int send_score, int size)
{
int hold = store_input(store_score, size);
int average = 0;
average = hold / 10;
return average;
}
void show()
{
int show = calculation(int send_score, int size);
cout << "The average is: " << show << endl;
}
**** Sorry for the sloppy code, I was trying to give you an idea of what I was trying to do ********
In this program, I am trying to send user input from the store_input() to the calculation(). The calculation function will then return the average which it will deliver to the show(). The show function will then display the average. I need an explanation on how I can send one function to another ? Also a quick explanation on how I should treat function arrays especially when transferring arrays to another function.