Why am I getting this error?

Can someone please tell me why I am getting this error?

1>c:\users\nbe4u\documents\visual studio 2008\projects\take 1000\take 1000\take 1000.cpp(16) : error C2664: 'calcAverage' : cannot convert parameter 1 from 'int' to 'int []'


This is the code:

#include <iostream>
#include <iomanip>
using namespace std;

//Function Prototype
void getValues();
void findLowest( int testScore[], int sz );
void calcAverage( int scores[], int lowest);

int main()
{
const int size=5;
int scores[size], lowest;

getValues();
calcAverage(scores[5], lowest);

return 0;
}



void getValues()
{
const int size = 5;
int scores[size];

cout << "Enter in " << size << " test scores and I will store ";
cout << "them in variables.\n";

for ( int i = 0; i < size; i++ )
{
cout << "Enter score " << ( i + 1 ) << " : ";
cin >> scores[i];
}

findLowest( scores, size ); // pass the address and size of the scores array

cout << fixed << showpoint << setprecision(2);
}


void findLowest( int testScore[], int sz )
{
int lowest = testScore[0];
for ( int i = 0; i < sz; i++ )
{
if ( testScore[i] < lowest )
{
lowest = testScore[i];
}
}

cout << "The lowest is " << lowest << endl;


}

void calcAverage (int scores[], int lowest)
{
double average = scores[1]+scores[2]+scores[3]+scores[4]+scores[5]-lowest/4;
}
You are calling calcAverage with a specific element of an array when it expects you to pass the entire array.
Code tags.
I fixed that, but now it aborts doing the program. Any suggestions?

I don't know what you mean by code tags. I'm so new to C++.
Code tags are a forum thing. No wonder you've made so many posts and completely ignored them.
http://www.cplusplus.com/articles/firedraco1/
Does it abort or does it just end after you finish running and immediately close? If the latter, read this thread: http://www.cplusplus.com/forum/beginner/1988/
If it's the former, I'll need some extra details if you have any.
a code tag simply means putting a [ code ] tag before your code and then a [/ code] tag at the end to make it easier to read
Well now it runs, but it is giving incorrect values. The averages are totally off. I think my calcAverage () is wrong. I tried using code tags? Just tell me if it's wrong, I'll fix it.



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <iomanip>
using namespace std;

//Function Prototype
void getValues();
void findLowest( int testScore[], int sz );
void calcAverage( int scores[], int lowest);

int main()
{


    getValues(); 
	
   
    return 0;
}



void getValues()
{
    const int size = 5;
    int scores[size];

    cout << "Enter in " << size << " test scores and I will store ";
    cout << "them in variables.\n";

    for ( int i = 0; i < size; i++ )
    {
        cout << "Enter score " << ( i + 1 ) << " : ";
        cin >> scores[i];
    }

    findLowest( scores, size ); // pass the address and size of the scores array

    cout << fixed << showpoint << setprecision(2);
}


void findLowest( int testScore[], int sz )
{
    int lowest = testScore[0];
    for ( int i = 0; i < sz; i++ )
    {
        if ( testScore[i] < lowest )
        {
            lowest = testScore[i];
        }
    }

    cout << "The lowest is " << lowest << endl;

	const int size=5;
	int scores[size];

	calcAverage (scores, lowest);
}

void calcAverage (int scores[], int lowest)
{
double average = ((scores[1]+scores[2]+scores[3]+scores[4]+scores[5])-lowest)/4;
cout <<" The average is" <<average;
}
That is correct use of code tags.
What kind of values are you getting for certain input? (And you may want to divide by 4.0. This avoids truncation of any floating points in the division process which will occur with int-only arithmetic.)
I added 4.0 just to try. It still hasn't fixed anything. I used 100,100,100,100, 50. It gets the right lowest value; however, it says my average is 13.5?
Topic archived. No new replies allowed.