gpt4 book ai didi

c - 我想用Visual Studio做一个 parking 收费程序

转载 作者:行者123 更新时间:2023-11-30 21:05:14 24 4
gpt4 key购买 nike

    int min1, min2, won;

printf("parking minutes(분)? ");
scanf("%d", &min1);

min2 = (min1 - 30) % 10;

if (min1 <= 39)
won = 2000;
else {
if (min2 = 0)
won = 2000 + 1000 * (min1 - 30) % 10;
else
won = 2000 + 1000 * (min1 - min2 - 20) % 10;
}
printf("parking fee: %d", won);

该计划的条件

  1. 直到30分钟,2000韩元
  2. 30分钟后,每10分钟1000韩元
  3. 每天最多 25000 韩元
  4. parking 时间不能超过 24 小时

我以为'%'表示余数,所以我就这样写,但是当我输入52时,结果显示5200!我想让结果为 5000。我想知道对于条件 3 和 4 该怎么办。我能做什么?我应该使用“for”和“sum”吗?

最佳答案

让我们按照与作业相同的顺序对步骤进行编程:

int min1, min2, won;

printf("parking minutes(분)? ");
if (scanf("%d", &min1) != 1) {
printf("invalid input\n");
return 1; // invalid input.
}

won = 2000; // 1. until 30min, 2000won, minimum price
if (min1 > 30) {
// 2. after 30min, 1000won per 10min
min2 = min1 - 30; // minutes after 30
// add 1000won for every slice or 10min or portion thereof
won += ((min2 + 9) % 10) * 1000;
// 3. max 25000won per a day
if (won > 25000)
won = 25000;
}
// 4. parking minutes cannot be over than 24 hours
if (min1 > 24 * 60) {
// reject request
printf("parking time exceeds 24 hours\n");
} else {
printf("parking fee: %d\n", won);
}

关于c - 我想用Visual Studio做一个 parking 收费程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55559577/

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