gpt4 book ai didi

rust - 如果不符合要求,即使应该满足

转载 作者:行者123 更新时间:2023-12-03 11:45:54 28 4
gpt4 key购买 nike

我正在做一个使用rust 的加类费计算器。我下面有以下代码:

let overhours = 40;
let overhoursFLOAT = overhours as f32;

if calcpay > overhours{
println!("You worked more than 40 hours!");
let overmath = floathours - overhoursFLOAT as f32;
println!("You worked {} extra hours.",overmath);
let overpay = overmath * 1.5;
floatpay = floatpay + overpay;
}
else{println!("You did not work more than 40 hours. Therefore, your overtime pay will not be calculated.");}

每次我运行它时,我输入的小时数(我做10个)都在40以下,并且if语句代码始终运行。最终看起来像这样:
How much do you get paid per hour?: 9
Hourly pay: 9
How much did you work?: 10
Hourly pay: 9
Hours worked: 10
Your calculated pay is $90
You worked more than 40 hours!
You worked -30 extra hours.

我使用运算符不正确吗?我怎样才能解决这个问题?

最佳答案

您将calcpay与加类时间进行比较,而calcpay等于90。我假设您想要的是将加类与工作时间进行比较。

关于rust - 如果不符合要求,即使应该满足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60698497/

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