You already have the code for the 1st 3 positions, what's not working is the last 3.
you do not need line 57 and 60
line 71-75 doesn't do what you think it does.
To make a function, take the code from main() and put in your function.
You have one called avg, so you already know how to make a function.
#include <iostream>
// #include <array>
usingnamespace std;
double avg(constdouble *begin, constdouble * end)
{
constdouble * pt;
double total = 0;
{
for (pt = begin; pt != end; pt++)
total = total + *pt;
}
return (total/(end - begin));
}
int myfunction ()
{
cout << "Please Enter The Number Of Scores You wish To Record, Up To 10 Different Scores" << endl;
int size;
std::cin >> size;
double*p = newdouble[size];
if (size > 10)
{
cout << "ILLEAGAL NUMBER OF SCORES ENTERED" << endl;
}
elseif (size == 0)
{
cout << "ILLEAGAL NUMBER OF SCORES ENTERED" << endl;
}
elsefor (int i = 0; i < size; i++)
{
cout << "Please Enter The Scores You Wish To Record" << endl;
std::cin >> p[i];
}
cout << "The Scores You Have Entered Are " << endl;
for (int i = 0; i < size; i++)
cout << p[i] << ",";
cout << " " << endl;
cout << "Your First 3 Scores Are: " << endl;
cout << p[0] << ',' << p[1] << ',' << p[2] << endl;
cout << "Their Average Is " << avg(p + 0, p + 3) << endl;
cout << "Your last 3 Scores Are: " << endl;
cout << p[size-3] << ',' << p[size-2] << ',' << p[size-1] << endl;
}
int main()
{
cout << "Hello Do You wish To Enter Your Golf Scores ?" << endl;
cout << "If Yes Enter Y, If No Enter N" << endl;
char ans;
std::cin >> ans;
if (ans == 'N')
{
cout << "Good Bye!" << endl;
}
elseif (ans == 'Y')
{
myfunction();
}
return 0;
}
Hello Do You wish To Enter Your Golf Scores ?
If Yes Enter Y, If No Enter N
Y
Please Enter The Number Of Scores You wish To Record, Up To 10 Different Scores
5
Please Enter The Scores You Wish To Record
11 22 33 44 55
Please Enter The Scores You Wish To Record
Please Enter The Scores You Wish To Record
Please Enter The Scores You Wish To Record
Please Enter The Scores You Wish To Record
The Scores You Have Entered Are
11,22,33,44,55,
Your First 3 Scores Are:
11,22,33
Their Average Is 22
Your last 3 Scores Are:
33,44,55