I'm new to C++ and have an assignment that requires four calculations that all build off of each other. The first is simple, with the requirement to provide the average for 4 defined numbers. I need the output from this file to print in the main cpp file, but I'm not able to get the value out to pass to the main file. I apprecate any input and feedback!
Below is the code for the header file, "average.h":
#ifndef AVERAGE_H_INCLUDED
#define AVERAGE_H_INCLUDED
using namespace std;
double getAverage(int Avg);
#endif
Below is the code for the "average.cpp" file:
#include <iostream>
#include <cmath>
using namespace std;
double getAverage(int avg)
{
int arr[] = { 24, 30, 40, 50 };
int size, i;
int Average, sum = 0;
size = sizeof(arr) / sizeof(arr[0]);
for (i = 0; i < size; i++)
sum = sum + arr[i];
Average = sum / size;
return Average;
}
void getAverage()
{
std::cout << Average << std::endl;
}
Below is the "main.cpp" file:
#include <iostream>
#include "average.h"
using namespace std;
int main()
{
cout << "The average of the four scores is: " << getAverage << endl;
}
I have tried numerous things and now I'm getting multiple errors and feel like I'm missing a few simple things. Any guidance and a little explanation of what I'm doing wrong would be very helpful.