Click here to Skip to main content
15,898,892 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;
//function prototype
int AVSD(double[], double&, double&, const int);
int max;	

int main() {
	const int SIZE = 10;
	int index = 0;
	double average = 0, SD = 0;
	double studyHour[SIZE] = {10,16,15.65,17,16.3,20,10.5,17.5,12 };

	index = AVSD(studyHour, average, SD, SIZE);
	cout << "Details of Practical Group 1" << endl;
	cout << "Average:" << average<<endl;
	cout << "Standard Deviation:" <<SD<< endl;
	cout << "Highest study hour" <<studyHour[max]<<endl;
	system("PAUSE");
	return 0;
}

int AVSD(double studyHour[], double& average, double& SD, const int SIZE) {

	double sum = 0;
	for (int i = 0; i < SIZE; i++) {
		sum = sum + studyHour[i];
		average = sum / SIZE;
	}

	double total = 0;
	for (int i = 0; i < SIZE; i++) {
		pow((studyHour[i] - average), 2);
		total += pow((studyHour[i] - average), 2);
	}
	SD = sqrt(fabs(total / SIZE));

	for (int i = 0; i < 10; i++) {
		if (i == 0) {
			max = i;
		}
		else {
			if (studyHour[i] > studyHour[max])
				max = i;
		}
return max;
	}
}


What I have tried:

I haven't try anything cause i don't really know what to do...
Posted
Updated 13-Aug-21 21:59pm
v2

It's because you have added
C++
using namespace std;
and declared a global variable:
C++
int max;
Since std contains std::max the compiler isn't sure which max you mean.

Change your variable name, or remove the using line.
 
Share this answer
 
OriginalGriff is right, but best is to remove all global variables not only because max is a bad and too short name.

When you read your code you will find that AVSD() is already returning the value and so you can work with that.
You also only need one loop in AVSD() and rethink your max calculation. I start with the first value outside the loop and than check for higher values.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900