This is my first post and I am just starting with arrays, but I am still stuck on how this function is suppose to work. I had to make two void functions and two-value returning functions. Main should call the getTestScores and get three test scores, then it should call calcAverage value returning function which calculates and returns the average then main should call displayAverage void function. This code does compile, but I am pretty sure that it is only because I tried to fix the mistakes rather than fix the code. I honestly do not know though how to formulate how I want to say it all within my code.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//Program functions
void getTestScores(int &num1,int &num2,int &num3);
double calcAverage(double calculation);
void displayAverage(double display);

int main ()
	//declared variables of main
	{ 
int score1 = 0;
int score2 = 0;
int score3 = 0;
double display = 0.0;
double calculation = 0.0;
  //starts program
getTestScores(score1, score2, score3);
calcAverage(calculation);
displayAverage(display);
system("pause");
return 0;
	}
//****Function Prototypes****
//gets the 3 test scores
void getTestScores(int &num1, int &num2, int &num3)
		{
  cout << "Enter first test score" << endl;
  cin >> num1;
  cout << "Enter second test score" << endl;
  cin >> num2;
  cout << "Enter third test score" << endl;
  cin >> num3;
		}
//calculates average
double calcAverage(double calculation)
			{
double average = 0.0;
int num1 = 0;
int num2 = 0;
int num3 = 0;
average = (num1 + num2 + num3) / 3;
calculation == average;
return calculation;
			}
//displays the average
void displayAverage(double display)
	{
cout << "The average of the three numbers is: " << display << endl;
	}

Below is the revised code: There were extra variables, and you were trying to pass the wrong parameter into calculation. Any questions, feel free to ask :)

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//Program functions
void getTestScores(int &num1,int &num2,int &num3);
double calcAverage(int num1, int num2, int num3);
void displayAverage(double display);

int main ()
	//declared variables of main
	{ 
int score1 = 0;
int score2 = 0;
int score3 = 0;
double calculation = 0.0;
  //starts program
getTestScores(score1, score2, score3);
calculation = calcAverage(score1, score2, score3);
displayAverage(calculation);
system("pause");
return 0;
	}
//****Function Prototypes****
//gets the 3 test scores
void getTestScores(int &num1, int &num2, int &num3)
		{
  cout << "Enter first test score" << endl;
  cin >> num1;
  cout << "Enter second test score" << endl;
  cin >> num2;
  cout << "Enter third test score" << endl;
  cin >> num3;
		}
//calculates average
double calcAverage(int num1, int num2, int num3)
			{
double average = 0.0;
average = (num1 + num2 + num3) / 3.0;
return average;
			}
//displays the average
void displayAverage(double display)
	{
cout << "The average of the three numbers is: " << display << endl;
	}

Thank you MasterGberry,

So I use the function of void for the referencing so that I can reference them into different functions since it holds my values that I will use later....why doesn't the book clearly state this ahhahaha. I have been racking my brain around it for a while and you solve my frustration in about 10 minutes -.-;;
Now its onto (which seem easier) arrays.

Oh I also forgot to set up the setprecision, but I have that under control : )

Cool, as long as you understand what needed to be done :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.