This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
sys_prog/midterm/tank_control/tank_control.c

47 lines
685 B
C

#include "tank_control.h"
unsigned int level = 0;
unsigned int cap = 1000000;
unsigned int bottle_size = 750;
unsigned int waste = 0;
void clear() {
waste = 0;
level = 0;
}
void change_bottle_capacity(unsigned int c) {
bottle_size = c;
}
void change_tank(unsigned int c) {
cap = c;
if (level > cap) {
waste += level - cap;
level = cap;
}
}
void add(unsigned int c) {
level += c;
if (level > cap) {
waste += level - cap;
level = cap;
}
}
unsigned int ship_out_bottles() {
unsigned int bottles = level / bottle_size;
level = level % bottle_size;
return bottles;
}
unsigned int get_tank_level() {
return level;
}
unsigned int get_wastes() {
return waste;
}