I am writing the following program that calculates the average of a group of test scores where the lowest score in the group is dropped. It has the following functions:

void getScore()-should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered.

void calcAverage() should calculate and display the average of the four highest scores. This function should be called just once by main and should be passed the five scores.

int findLowest(): should find and return the lowest of the five scores passed to it. It should be called by the calcAverage, who uses the function to determine which of the five scores to drop.

So far, here is my version of the program:

#include <iostream>
#include <iomanip>
using namespace std;

void getscore(int, int, int, int, int);
int findLowest (int, int, int, int, int);
void calcAverage (int, int, int, int, int, int);

int main()
{
int average, score1, score2, score3, score4, score5;
getscore (score1, score2, score3, score4, score5);
calcAverage (average, score1, score2, score3, score4, score5);
return 0;
}

void getscore (int score1, int score2, int score3, int score4, int score5)
{
cout << "Enter first score: ";
cin >> score1;
cout << "Enter second score: ";
cin >> score2;
cout << "Enter third score: ";
cin >> score3;
cout << "Enter fourth score: ";
cin >> score4;
cout << "Enter fifth score: ";
cin >> score5;
}
void calcAverage (int average, int score1, int score2, int score3, int score4, int score5)
{
int small=findLowest(score1,score2,score3,sc…
average = ((score1 + score2 + score3 + score4 + score5)-small)/4;
cout << average;
}
int findLowest(int score1, int score2, int score3, int score4, int score5)
{
int small =score1;
if(small>score2)
{
small=score2;
}
if(small>score3)
{
small=score3;
}
if(small>score4)
{
small=score4;
}
if(small>score5)
{
small=score5;
}
return small; 
}

I am getting errors such as:

----unresolved external symbol "void __cdecl calcAverage(int,int,int,int,int)" (?calcAverage@@YAXHHHHH@Z) referenced in function _main

----error LNK2019: unresolved external symbol "void __cdecl getscore(int &,int &,int &,int &,int &)" (?getscore@@YAXAAH0000@Z) referenced in function _main

PLEASE HELP!!!

Well the first major problem is that you are not passing the variables by reference to GetScore, so they aren't going to be available when you leave it!

Davidoria is right on this first part. Because getscore is a void function, thus isn't returning the scores, you must pass the scores by reference. Doing this updates the scores in int main() where the calcAverage function receives the scores.

Next, you may want to consider moving the findLowest function outside of the calcAverage function. This would include adding the findLowest function to int main(), and then sending the "small" that it returns to the calcAverage function (there are some other minor things doing this entails that I am sure you can figure out).

I did get your program to run correctly by making this change. Let me know if you have any more questions.

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.