Skip to content

Commit

Permalink
Merge pull request condo4#19 from miska/master
Browse files Browse the repository at this point in the history
Better formula to compute total consumption
  • Loading branch information
condo4 committed Jun 10, 2015
2 parents 4916375 + d8740c9 commit c1b9535
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,24 +362,24 @@ double Car::consumption() const
unsigned long int maxDistance = 0;
unsigned long int minDistance = 999999999;
double totalConsumption = 0;
double partConsumption = 0;

foreach(Tank *tank, _tanklist)
{
if(tank->distance() > maxDistance)
maxDistance = tank->distance();
if(tank->distance() < minDistance)
minDistance = tank->distance();
totalConsumption += tank->quantity();
}
if(maxDistance == 0) return 0;
foreach(Tank *tank, _tanklist)
{
if(tank->distance() == minDistance)
if(tank->full())
{
totalConsumption -= tank->quantity();
break;
totalConsumption += partConsumption;
partConsumption = 0;
if(tank->distance() > maxDistance)
maxDistance = tank->distance();
if(tank->distance() < minDistance)
minDistance = tank->distance();
}
if(maxDistance > 0)
partConsumption += tank->quantity();

}
if((maxDistance == 0) || (maxDistance == minDistance)) return 0;
return totalConsumption / ((maxDistance - minDistance)/ 100.0);
}

Expand Down

0 comments on commit c1b9535

Please sign in to comment.