Originally Posted by
grumpy
Overloading of functions just refers to two functions, with the same name, accepting different types of arguments.
So break your code up into parts that can be placed into separate functions - cases where it is doing the same basic thing, but with different data, are obvious candidates. Then among those functions look for a case where those functions do essentially the same thing, but on different argument types.
So I tried implementing your advice, my program is definitely not working now and I do not even understand the error the compiler is giving me. I am required to have 4 overloaded functions. The compiled is telling me Unresolved External 'yer (int)'
Code:
#include <string>
#include <iostream>
using namespace std;
double yer( int p );
double yer( int p, double m )
{
return p/m;
}
double yer( int p, int r, double m )
{
return (p+r) / m;
}
double yer( int p, int r, int a, double m )
{
return (p+r+a) / m;
}
int main()
{
int pts, rbd, ast;
double min, per, per2, per3, per4, pert;
cout<< "Enter points scored: \n";
cin>> pts;
cout<< "Enter time played in minutes: \n";
cin>> min;
cout<< "Enter rebounds: \n";
cin>> rbd;
cout<< "Enter assists: \n";
cin>> ast;
per = yer (pts);
per2 = yer (pts / min);
per3 = yer (pts + rbd / min);
per4 = yer (pts + rbd + ast / min);
pert = ((per+per2+per3+per4) / 4)* 10;
cout<< "Player Efficiency Rating is:" << pert << endl;
return 0;
}