gpt4 book ai didi

C编程: I want subtract a weight per second

转载 作者:行者123 更新时间:2023-11-30 20:25:54 26 4
gpt4 key购买 nike

我是 stackoverflow 的新手,如果我犯了错误,我很抱歉。

我是 C 语言初学者,我有一个项目需要每秒减去一个重量。例如重量:50公斤每秒减去4%

我找到了这段代码

while(waitFor(1))
{
*weight=(*weight)-(*weight)*0.4;
}

void waitFor(int secs)
{
int retTime;
retTime = time(0) + secs; // Get finishing time.
while (time(0) < retTime); // Loop until it arrives.
}

但我不想等待 x 秒才能完成。我想要更快的解决方案。有什么想法

**注意:我想知道权重为0需要多少秒 sleep 命令在我的电脑上不起作用。**

For cleaning and disinfecting of the pool dropped into the water of a chemical a solid body. This solid body upon contact with water immediately begins to dissolve, losing weight equal to 4% by mass per second. If the dissolution rate of the chemical remains constant, to implement program will accept the weight of the solid body in grams and displays after how time will completely dissolve. The time is displayed in a "hours: minutes: seconds". For example, if the dissolution time is 3,740 seconds, displaying 01: 02: 20. To calculate the time you need to implement a function which accepts gram and return the three time parameters ie hours, minutes and seconds. Note that the time printed on the main function.

最佳答案

您可以在循环中使用 sleep(int) 函数,它将等待暂停进程直至达到整数值。

  while((1) && weight > 0)
{
sleep(1);
*weight=(*weight)-(*weight)*0.4;
}

等待1秒后进行减法,连续运行

关于C编程: I want subtract a weight per second,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27331011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com