我遇到了一个问题,制定了一个公式,用于计算大坝空洞或填充所需的DAYS数量。这就是一个名为Dam的公共课。
基本上我有:
int capacity = 3538000; // acreFT
int storage = 1796250; // acreFT
int inflowRate = 1050; // cubic-FT/sec
int outflowRate = 2530; // cubic-FT/sec
然后我发表if-else
声明,说:
if(inflow > outflow)
{
//formula here
}
else if (outflow > inflow)
{
//formula here
}
else
{
return -1; // if dam inflow/outflow is equal basically, "holding."
}
我如何在这里使用公式?如果我开始;
if(outflow > inflow)
{
int data = outflow - inflow; // still in cubic-ft per sec
// convert data to acresFT? using some sort of conversion variable?
// then using new variable for the converted data * storage..?
// then finally times by second in a day (86400 seconds, another variable established at the top of my program.)
}
阅读起来可能非常粗略,但我不想在这里上传我的整个文件。
答案 0 :(得分:2)
我将变量的含义如下
capacity as the total volume of water it can hold
storage as the total volume of water it currently holds
inflow as volume of water flowing into the dam per second
outflow as volume of water flowing out of the dam per second
int flow_rate_difference = 0 ;
Long dam_fill_seconds = 0;
Long dam_empty_seconds = 0;
if(inflow > outflow)
{
//we have to calculate the amount of seconds it will take to fill the dam
// 1 acre foot = 43560.0004435. I am taking 43560 plz use full value if you require more accuracy
// conversion taken from http://www.convertunits.com/from/cubic+foot/to/acre+foot
// total capacity 3538000acrefoot
// current capacity = total capacity - stored capacity ie (3538000-1796250) acrefoot
// current capacity in cubic foot (3538000-1796250)*43560
// at the same second water is flowing into and out of dam . but if inflow is higher then that difference we have to calculate
flow_rate_difference = inflowRate - outflowRate;
// total sec required to fill dam is current capacity / flow_rate_difference
dam_fill_seconds = (3538000-1796250)*43560/flow_rate_difference ;
}
if (outflow > inflow )
{
//time for dam to be empty
flow_rate_difference = outflowRate-inflowRate;
//here we just need to take stored capacity
dam_empty_seconds = storage*43560/flow_rate_difference;
}