Home > Mobile >  While loop function in C language to create a tank to sum my annual increment
While loop function in C language to create a tank to sum my annual increment

Time:10-16

Hi guys I would like to calculate the annual increment of my water flux every year of simulation using a while loop. My model can simulate every year water flux. For example:

double WaterTank = 0;
s->value[FLUX_WATER];
s->value[MAX_WATER];

if (s->value[FLUX_WATER] > 0.) {

while (WaterTank <= s->value[MAX_WATER]) {

     WaterTank = WaterTank   s->value[FLUX_WATER];

     WaterTank  ;

}

The first problem is: my water flux usually is 0.35ml per year and I put the limit of 1l to the MAX_WATER before emptying. The second one is: I can't increment (1 unit) because my cycle stopped early. I would like to sum every year until my tank reaches 1 liter (e.g 1year >> 0.35 >> 2ndyear 0.35 0.15 >> 3rd year 0.5 0.4 >> 4th year 0.9 0.1 (stop))

Any help? thank you!!

CodePudding user response:

You need to check if you've gone over MAX_WATER after you add the flux, and cap it to the limit.

while (true) {
    WaterTank  = s->value[FLUX_WATER];
    if (WaterTank > s->value[MAX_WATER]) {
        WaterTank = s->value[MAX_WATER];
        break;
    }
}
  • Related