gpt4 book ai didi

C# 减脂计算器

转载 作者:太空宇宙 更新时间:2023-11-03 21:36:04 25 4
gpt4 key购买 nike

您好,我正在尝试让我的代码计数为 10、15、20、25....60,然后将每个计数乘以 3.9cal 并显示两者,但出于某种原因,我的代码不会倒计时,您能帮帮我吗?

请保持代码简单,因为我还在学习:)

double lost;
int counter = 5;
while (counter <= 60)
{
if (counter * 5 == 0)
{
lost = counter * 3.9;
Console.WriteLine("Minutes spend: {0} Fat Lost: {1}", counter, lost);
counter++;
}

Console.ReadLine();
}

最佳答案

您的代码的问题是您的 IF 语句永远不会为真,因为您开始使用 counter = 5 开始循环

您需要将 counter++ 移到 if 语句之外才能解决问题

double lost;
int counter = 5;
while (counter <= 60)
{
if (counter % 5 == 0)
{
lost = counter * 3.9;
Console.WriteLine("Minutes spend: {0} Fat Lost: {1}", counter, lost);
}
counter++;
}
Console.ReadLine();

关于C# 减脂计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21786473/

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