average array functions

i am trying to pass the total number of entries to a function calcaverage and make it average while dropping the lowest grade and returning the average back to main so far here is what i got any help would be appreciated


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

const int GradeArray = 6;

void calcaverage (double userinput)
{
	double total =0;
	double average;
	for (int count =0;count <GradeArray;count++);
	
		total+=GradeArray[count];

}
int main()
{
	double userinput[GradeArray];
	double total=0,average;

	//input grades
	cout << "please enter 6 test scores:"<<endl; 
	for (int count=0;count < GradeArray;count++)
	{
		cout<< "test #" << (count + 1) <<":";
		cin >> userinput[count];
		calcaverage (userinput);

	}
 }
Last edited on
Put your code into proper code tags please.
Zaita?!? Where in the world have you been?

Also, you can pass arrays to functions. Note that they are passed by reference.
http://cplusplus.com/doc/tutorial/arrays/

-Albatross
Me? Working, Diving; Usual life stuff mostly. Just got fed up with all the stupid questions people asked every day so decided to take a break. I'm not really back, just killing some time while I wait for a large compilation at work :)
sorry but i seem to still be missing simething here i am trying to pass userinput into the function but continue to get errors like
error C2664: 'calcaverage' : cannot convert parameter 1 from 'double [6]' to 'double'
1
2
3
4
void calcAverage(double userInput[])
{
 
}

Last edited on
i appreciate the help but now iv really gone off the deep end and screwed myself and i could be more confused with my own code (damn) lol

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;


const int GradeArray = 6;
void LowestScore()
{
	double lowest,count;
	double userinput[GradeArray];

	lowest=userinput[0];
	for (count=0;count<GradeArray;count++)
	{
		if (userinput[count] < lowest)
			lowest=userinput[count];
	}

}
void calcaverage (double userinput[])
{
	double userinput[GradeArray];
	double total =0;
	double average;
	int count=0;
	for (int count =0;count <GradeArray;count++);
	{
		total+=GradeArray[count];
		average=total/GradeArray;
	}
}
int main()
{
	double userinput[GradeArray];
	double total=0,average;
	

	//input grades
	cout << "please enter 6 test scores:"<<endl; 
	for (int count=0;count < GradeArray;count++)
	{
		cout<< "test #" << (count + 1) <<":";
		cin >> userinput[count];
		double calcaverage (double userinput);

	}
 }
Last edited on
Please think carefully about what you need to achieve and what steps you need to go through and it do.

For example. You're calculating the average (line 45) in the middle of a for loop before you've grabbed all of the results. Your method declarations are incorrect. Please read:
http://www.cplusplus.com/doc/tutorial/functions/ and http://www.cplusplus.com/doc/tutorial/functions2/

Your original code was closer to solving your problem than your latest attempt.
thanks for the push in the right direction if your interest ill keep you posted
Last edited on
i finally got it to get the lowest i just need it to drop it now




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

const int GradeArray = 6;

void calcaverage()
{

}

int main()
{
	double userinput[GradeArray];
	double total=0,average;
	float lowest;
	
	cout << "please enter 6 test scores:"<<endl; //input grades loop
	for (int count=0;count < GradeArray;count++)
	{
		cout<< "test #" << (count + 1) <<":";
		cin >> userinput[count];
	}

	lowest = userinput[0];
	for ( int count = 1; count < GradeArray; count++)//find lowest grade loop
	{
		if(userinput[count] < lowest)
			lowest = userinput[count];
	
	}
	
 }
thanks zaita for your help
Topic archived. No new replies allowed.