问答详情
源自:5-14 综合练习

人麻了,怎么让返回值返回实型啊

#include <stdio.h> 

int getPrice(int distance,int time) {

float cost;

if (distance <= 3) {

cost = 14;

}

else

{

if (time >= 5 && time < 23) {

cost = (distance - 3) * 2.3 + 14;

}else {

cost = (distance - 3) * 2.3 * 1.2 + 14;

}

}

return cost;

}

int main() {

int distance,time;

float cost;

distance = 12;

time = 9;

float cost1=getPrice(distance, time);

time = 18;

float cost2 = getPrice(distance, time);

cost = cost1 + cost2;

printf("小明每天要花%f元坐车", cost);

return 0;

}


提问者:唯你人间星火 2022-02-14 16:04

个回答