Friday, September 28, 2007

The Trip

I have absolutely no clue of why This one is getting a WRONG ANSWER !!!!
____________________________________________________________________
Question: The Trip
____________________________________________________________________

#include "iostream.h"
#include "math.h"

int main()
{
double sum;
float avg, arr[1000], xchg, diff;;
int n;
while(true) {
cin >> n;
if(n == 0) break;
sum = 0;
for(int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
avg = sum / n;
avg = floor(avg * 100 + 0.5) / 100;
xchg = 0;
for(int i = 0; i < n; i++) {
diff = arr[i] - avg;
if(diff > 0) xchg += diff;
}
cout << "$" << xchg << endl;
}
return 0;
}
____________________________________________________________________

No comments:

Contributors