Find amount of water wasted after filling the tank in C++

In this tutorial, we are going to solve the following problem.

Given a tank with a capacity of N liters and a pump that fill the tank with S speed per minute. Unfortunately, there is a hole in the tank. And water is wasting at a speed of WS per minute while filling it.

We need to calculate the amount of water wasted for a full tank.

The amount of water filled per minute is equal to the difference between the water filling water and wasting water speed.

Hence we can get the total time to fill the water tank by dividing the capacity of the water tank by the filling speed per minute.

And we can easily get the wastage of water by multiplying the wasting water speed with the time to fill the water tank.


Let's see the code.

 Live Demo

#include <iostream>
using namespace std;
double countTheWastedWater(double N, double S, double WS) {
   double wasted_water, fill_per_minute, time_to_fill;
   fill_per_minute = S - WS;
   time_to_fill = N / fill_per_minute;
   wasted_water = WS * time_to_fill;
   return wasted_water;
int main() {
   double N, S, WS;
   N = 275;
   S = 10;
   WS = 3;
   cout << countTheWastedWater(N, S, WS) << endl;
   return 0;


If you execute the above program, then you will get the following result.



If you have any queries in the tutorial, mention them in the comment section.