Paradox with averages Programming problem
I have an class of Computer Science students represented with an array, and a class of Economics students also represented as an array.
The array is filled with values representing each students IQ.
One well-known joke goes as follows: If a bad Computer Science student drops out of college and goes to a different college to study Economics instead, he will increase the average intelligence on both colleges.
I have to run through the computer science array and check if each student leaves and joins economics, will he increase the average IQ of both groups. I then have to count how many students and print to the screen.
I seem to have gotten the right answer but one of the test cases is wrong, can anyone lay their wisdom upon me? thanks.
int main() {
int cases;
cin >> cases;
for(int i = 0; i < cases; i++)
{
int numCs;
int numEc;
cin >> numCs;
cin >> numEc;
int csArray[numCs];
int ecArray[numEc];
long csTotal = 0;
long ecTotal = 0;
for(int j = 0; j < numCs; j++)
{
cin >> csArray[j];
csTotal += csArray[j];
}
for(int j = 0; j < numCs; j++)
{
cin >> ecArray[j];
ecTotal += ecArray[j];
}
double csAvg = csTotal / (double)numCs;
double ecAvg = ecTotal / (double)numEc;
int count = 0;
for(int j = 0; j < numCs; j++)
{
if((csArray[j] < csAvg) && (csArray[j] > ecAvg))
{
count++;
}
}
cout << count << endl;
}
return 0;
}