gpt4 book ai didi

c - parking 收费计划

转载 作者:行者123 更新时间:2023-11-30 21:39:01 26 4
gpt4 key购买 nike

编写一个程序,在给出以下信息时计算将车停在 parking 场的顾客的 parking 费:

a.显示车辆类型的字符:C 代表轿车,B 代表巴士,T 代表卡车

b. 0 到 24 之间的整数,显示车辆进入 parking 场的时间。

c. 0 到 60 之间的整数,显示车辆进入 parking 场的分钟。

d. 0 到 24 之间的整数,显示车辆离开 parking 场的时间。

e. 0 到 60 之间的整数,显示车辆离开 parking 场的分钟数。

由于这是一个公共(public) parking 场,因此鼓励人们只 parking 很短一段时间。管理层对每种类型的车辆采用两种不同的费率。

enter image description here

当晚午夜,任何车辆不得在 parking 场停留;它将被拖走。 parking 费还需缴纳 6% 的消费税。

g。编写一个程序i.显示介绍信息二.提示用户输入相关信息。三.使用以下格式显示帐单。

h。您的计划将包括以下标准。我。验证入时和超时。二.使用 switch 语句来区分不同类型的车辆。三.使用适当的循环语句以允许重复计算 parking 费四.使用表 1 使用适当的测试数据运行程序五次

enter image description here

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char type; //Variable for vehicle types
int hourIn, minuteIn, hourOut, minuteOut, entry, exit, totalParkingTime; //Variable for time
float totalRounded, totalChargeFee, GST; //Variable for fare

printf("Welcome to Help Parking Lot!\n"); //Introduction message

printf("Enter type of vehicle: %c", type); //Type of vehicles: C for car, T for truck, B for bus
scanf("%c", &type);

switch(type)
{
case 'C':
if(totalParkingTime <= 3)
totalChargeFee = 0.8 * totalParkingTime;
else
totalChargeFee = 0.8 * 3 + 1.5 * (totalParkingTime - 3);
break;

case 'T':
if(totalParkingTime <= 2)
totalChargeFee = 1.5 * totalParkingTime;
else
totalChargeFee = 1.5 * 2 + 2.3 * (totalParkingTime - 2);
break;

case 'B':
if(totalParkingTime <= 1)
totalChargeFee = 2 * totalParkingTime;
else
totalChargeFee = 2 * 1 + 3.4 * (totalParkingTime - 1);
break;
}
scanf("%f", &totalChargeFee);

printf("Enter an integer between 0 and 24 showing the hour the vehicle entered the lot: %d", hourIn); //The hour of veicle enter in military format
scanf("%d", &hourIn);
printf("Enter an integer between 0 and 60 showing the minute the vehicle entered the lot: %d", minuteIn); //The minute of vehicle enter in military format
scanf("%d", &minuteIn);
printf("Enter an integer between 0 and 24 showing the hour the vehicle exited the lot: %d", hourOut); //The hour of vehicle exit in military format
scanf("%d", &hourOut);
printf("Enter an integer between 0 and 60 showing the minute the vehicle exited the lot: %d", minuteOut); //The minute of vehicle exit in military format
scanf("%d", &minuteOut);

entry = hourIn + minuteIn;
scanf("%d", &entry);
exit = hourOut + minuteOut;
scanf("%d", &exit);
totalParkingTime = exit - entry;

//User's bill is shown here
printf("HELP PARKING LOT CHARGE\n Type of vehicle: %c\n TIME-IN\n \t\t\t %d:%d\n TIME-OUT\n \t\t\t %d:%d\n \t\t\t------\n PARKING TIME %d:%d\n ROUNDED TOTAL \t\t\t%f\n \t\t\t------\n TOTAL CHARGE \t\t RM%.2f\n GST \t\t\t RM%.2f\n TOTAL \t\t\t RM%.2f");

return 0;
}

我不知道如何让它计算时间和超时的小时和分钟差异以及车辆的类型。当我运行程序时,时间输入有错误。但显示格式是正确的。

最佳答案

你意识到这里了吗:

if(type == 'C' && totalHourParked <= 3)
{
totalChargeFee = 0.8 * totalHourParked;
}
else
{
totalChargeFee = 1.5 * totalHourParked;
}

所有B&T类型都会进入else语句吗?

在尝试编码之前,我鼓励您拿起纸和笔并尝试编写某种伪代码。之后,尝试手动测试。如果您对此有信心,请对其进行编码。测试一下。如果这些都不起作用,那么请将你的问题暴露给 stackoverflow。

关于c - parking 收费计划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42548488/

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