Hello all,
I'm in my first C++ class and in this chapter we are learning about functions. my assignment is to create a program that uses 3 functions and calls these functions in main. the functions are getScore, calcAverage and findLowest; they should be self explanatory.
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 test score to be entered
void calcAverage should calculate and display the aver 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 calcAverage, which uses the function to determine which of the five scores to drop
below is my code. When i run it i get an
error LNK2019: unresolved external symbol "int __cdecl findLowest(int,int,int,int,int)" (?findLowest@@YAHHHHHH@Z) referenced in function "void __cdecl calcAverage(int,int,int,int,int)" (?calcAverage@@YAXHHHHH@Z)
Code:
#include <iostream>
using namespace std;
void getScore(int&);
void calcAverage(int, int, int, int, int);
int findLowest(int, int, int, int, int);
int main()
{
int score1,score2,score3,score4,score5;
getScore(score1);
getScore(score2);
getScore(score3);
getScore(score4);
getScore(score5);
calcAverage(score1, score2, score3, score4, score5);
system("pause");
return 0;
}
void getScore(int &score)
{
cout << "Please enter a test score. ";
cin >> score;
while (score < 0 || score > 100)
{
cout << "Valid test scores range from 0 - 100.\n";
cout << "Please enter a test score. ";
cin >> score;
}
}
void calcAverage(int score1, int score2, int score3, int score4, int score5)
{
float average;
int low = findLowest(score1, score2, score3, score4, score5);
if ( low == score1 )
{average = static_cast<float> (( score2 + score3 + score4 + score5 ) / 4 );}
else if ( low == score2 )
{average = static_cast<float> (( score1 + score3 + score4 + score5 ) / 4 );}
else if ( low == score3 )
{average = static_cast<float> (( score1 + score2 + score4 + score5 ) / 4 );}
else if ( low == score4 )
{average = static_cast<float> (( score1 + score2 + score3 + score5 ) / 4 );}
else
{average = static_cast<float> (( score1 + score2 + score3 + score4 ) / 4 );}
cout << "The Average of the scores is: " << average << endl;
}
int findlowest( int score1, int score2, int score3, int score4, int score5 )
{
if ( score1 <= score2 && score1 <= score3 && score1 <= score4 && score1 <= score5 )
{return score1;}
else if ( score2 <= score1 && score2 <= score3 && score2 <= score4 && score2 <= score5 )
{return score2;}
else if ( score3 <= score1 && score1 <= score2 && score3 <= score4 && score3 <= score5 )
{return score3;}
else if ( score4 <= score1 && score4 <= score2 && score4 <= score3 && score4 <= score5 )
{return score4;}
else
{return score5;}
}