Skiena's Programming Challenge [UVa ID 10137]- Getting WA Question from Skiena's Programming Challenges. 
Getting WA (wrong answer) in Online Judge even though it's working for sample test cases. Can somebody find a case where it fails?

I tried the tricky case from this link and it gave the right answer-

&quot;The Trip&quot; challenge from Programming Challenges

Input

Standard input will contain the information for several trips. Each trip consists of a
line containing a positive integer n denoting the number of students on the trip. This is
followed by n lines of input, each containing the amount spent by a student in dollars
and cents. There are no more than 1000 students and no student spent more than
$10,000.00. A single line containing 0 follows the information for the last trip.

Output

For each trip, output a line stating the total amount of money, in dollars and cents,
that must be exchanged to equalize the students’ costs.

Sample Input
3
10.00
20.00
30.00
4
15.00
15.01
3.00
3.01
0

Sample Output
$10.00
$11.99

#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;sstream&gt;
using namespace std;

int main()
{   vector &lt;float&gt; nums;
    int numStudents,loopVar1,pos;
    float amount,sum=0,roundAmt,ans;
    string strAns;
    stringstream ss;
    while(cin&gt;&gt;numStudents) {
        if(numStudents==0)
            break;
        ans=sum=0;
        nums.erase(nums.begin(),nums.end());
        for(loopVar1=0;loopVar1&lt;numStudents;loopVar1++) {
            cin&gt;&gt;amount;
            nums.push_back(amount);
            sum+=amount;
        }
        sum/=numStudents;
        roundAmt=(int)(sum*100);
        roundAmt/=100.0f;
        //cout&lt;&lt;roundAmt&lt;&lt;"\n";
        for(loopVar1=0;loopVar1&lt;numStudents;loopVar1++)
            if(nums[loopVar1]&lt;roundAmt)
                ans+=(roundAmt-nums[loopVar1]);
        strAns="";
        ss.str("");
        ss&lt;&lt;ans;
        strAns=ss.str();
        pos=strAns.find('.');
        if(pos==-1)
            strAns+=".00";
        else
            strAns.erase(pos+3);
        cout&lt;&lt;'$'&lt;&lt;strAns&lt;&lt;"\n";
    }
    return 0;
}
I did not run it (and I do not like to read it, too much abbreviations, wrong variable names, too less formatting), but what about this case:


  3
  1.01
  0.99
  0.99  


sum will be 2.99 / 3 = 0.9966666... 
roundAmt will be 0.99
ans will be 0
Obviously, it should be 0.01 to fulfill the requirement "so that the net cost to each is the same, to within one cent"

Beside this, please consider the things I mentioned in the beginning. Some concrete examples:


  sum/=numStudents;


This is not a sum anymore, it is the average.


  loopVar1


Take i, this is expected for a loop variable


  numStudents


Could be: number_of_students or numberOfStudents

for(loopVar1=0;loopVar1&lt;numStudents;loopVar1++)


Could be: for (i = 0; i &lt; number_of_students; ++i)

for(loopVar1=0;loopVar1&lt;numStudents;loopVar1++)
            if(nums[loopVar1]&lt;roundAmt)
                ans+=(roundAmt-nums[loopVar1]);


One could discuss if using the short form without brackets is ok for one line statements, but if it spans over multiple lines, please use brackets, even if it is syntactically ok.

what does roundAmt mean?

and so forth.