# C++ Program to check if tank will overflow, underflow or filled in given time

Given with the rate of filling the tank, height of a tank and radius of a tank and the task is to check whether the tank is overflow, underflow and filled in given time.

## Example

Input-: radius = 2, height = 5, rate = 10
Output-: tank overflow
Input-: radius = 5, height = 10, rate = 10
Output-: tank undeflow

Approach used below is as follows

• Input the rate of filling time, height and radius of a tank
• Calculate the volume of a tank to find the original rate of flow of water.
• Check for the conditions to determine the result
• If expected < original than tank will overflow
• If expected > original than tank will underflow
• If expected = original than tank will fill on time
• Print the resultant output

## Algorithm

Start
Step 1->declare function to calculate volume of tank
return ((22 / 7) * rad * 2 * height)
step 2-> declare function to check for overflow, underflow and filled
void check(float expected, float orignal)
IF (expected < orignal)
Print "tank overflow"
End
Else IF (expected > orignal)
Print "tank underflow"
End
Else
print "tank filled"
End
Step 3->Int main()
Set int rad = 2, height = 5, rate = 10
Set float orignal = 70.0
Set float expected = volume(rad, height) / rate
Call check(expected, orignal)
Stop

## Example

Live Demo

#include <bits/stdc++.h>
using namespace std;
//calculate volume of tank
float volume(int rad, int height) {
return ((22 / 7) * rad * 2 * height);
}
//function to check for overflow, underflow and filled
void check(float expected, float orignal) {
if (expected < orignal)
cout << "tank overflow";
else if (expected > orignal)
cout << "tank underflow";
else
cout << "tank filled";
}
int main() {
int rad = 2, height = 5, rate = 10;
float orignal = 70.0;
float expected = volume(rad, height) / rate;
check(expected, orignal);
return 0;
}

## Output

tank overflow