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;
}
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.
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.
#include <iostream>
#include <iomanip>
usingnamespace std;
//Function Prototype
void getValues();
void findLowest( int testScore[], int sz );
void calcAverage( int scores[], int lowest);
int main()
{
getValues();
return 0;
}
void getValues()
{
constint 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;
constint 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?