Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C++ code - Calculate Average Scores Using Array

Status
Not open for further replies.

thanglong

Junior Member level 3
Joined
Oct 6, 2006
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,452
Dear All,

Does anyone have C++ source code that calculates average scores using array? Please share!

Thank You!
 

double GetMean(double daArray[], int iSize) {
double dSum = daArray[0];
for (int i = 1; i < iSize; ++i) {
dSum += daArray;
}
return dSum/iSize;
}

int main()
{
double dValues[] =
{3.4, 4.8, 8.4, 9.6, 2.3, 9.6, 5.6, 9.6, 4.8, 2.2};
int iArraySize = 10;

std::cout << "Mean = "
<< GetMean(dValues, iArraySize) << std::endl;

return 0;
}


Regards,
ALPER USLU
 

Thanks for the source code.

How do I allow users to input a list of numbers?
 

here's what you can do

int main()
{
double *dValues = 0;
int iArraySize = 0;

cout << "please enter the size of the array";
cin >> iArraySize;

dValues = new double[iArraySize];

for(int i=0; i < iArraySize;i++)
{
cout << "Please enter the number:";
cin >> dValues;
cout << endl;

}

std::cout << "Mean = "
<< GetMean(dValues, iArraySize) << std::endl;

delete [] dValues;

return 0;
}
 

You guys are super! Thanks a lot for your help
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top