当我运行它时说:
incompatible pointer to integer conversion passing int (int, int) to the parameter of type char [-Wint-conversion]
我不确定如何解决此问题,因为它需要一个char值来确定“ if”语句,所有帮助都将得到赞赏。
//此程序需要停放的时间和剩余的时间(以军事时间为单位)和一个字符(C,B,T)来确定停车费。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// ---------------------func calc minutes parked -----------------------//
int total_minute_parked (int minute_in, int minute_left)
{
int minute_parked;
if (minute_left > minute_in)
{
minute_parked = abs((minute_left + 60) - minute_in);
}
else
{
minute_parked = abs(minute_left - minute_in);
}
return minute_parked;
}
// ---------------func calc total hours parked ----------------------//
int total_hour_parked (int hour_in, int hour_left)
{
int hours_parked;
if (hour_left > hour_in)
{
hours_parked = abs((hour_left - 1) - hour_in);
}
else
{
hours_parked = abs(hour_left - hour_in);
}
return hours_parked ;
}
// funtion to calc charge based off type of vehicle
float amount_charged (char vehicle_type,int total_hour_parked)
{
char C;
char T;
char B;
float temp_charged;
if (vehicle_type == C) // ------------------------------------CAR
{
if (total_hour_parked > 3)
{
float secondary_hour = total_hour_parked - 3;
temp_charged = secondary_hour * 1.5;
}
else
{
temp_charged = 0;
}
}
else if (vehicle_type == T) // -----------------------------TRUCK
{
if (total_hour_parked > 2)
{
float secondary_hour = total_hour_parked - 2;
temp_charged = (secondary_hour * 2.3) + 1;
}
else {
temp_charged = 1;
}
}
else if (vehicle_type == B) // --------------------------------BUS
{
if (total_hour_parked > 1)
{
float secondary_hour = total_hour_parked - 1;
temp_charged = (secondary_hour * 3.7) + 2;
}
else {
temp_charged = 2;
}
}
return temp_charged;
}
// main that prints results and takes imput
// ------------------------结果打印在主----------------- -------- //
int main()
{
int total_hour_parked (int hour_in,int hour_left);
char vehicle_type;
int hour_in = 0;
int minute_in = 0;
int hour_left = 0;
int minute_left = 0;
printf("Please enter the type of Vehicle:"); scanf("%c",&vehicle_type);
printf("Please enter the hour entered lot:"); scanf("%d", &hour_in);
printf("Please enter the minute entered lot:"); scanf("%d", &minute_in);
printf("Please enter the hour left lot:"); scanf("%d", &hour_left);
printf("Please enter the minute left lot:"); scanf("%d", &minute_left);
printf("Parking time: %d:%d\n", total_hour_parked(hour_in,hour_left),total_minute_parked(minute_in,minute_left));
printf("Cost %f",amount_charged(total_hour_parked,vehicle_type));
return 0;
}
答案 0 :(得分:1)
您的参数放置在错误的位置。您的功能
float amount_charged (char vehicle_type,int total_hour_parked)
但是当您打印出来
printf("Cost %f",amount_charged(total_hour_parked(hour_in,hour_left),vehicle_type));