栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

cyuyanshiyanbaogaodan

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

cyuyanshiyanbaogaodan

include

////////函数的返回值 ,函数名,函数的参数:时间,距离 ,任何一个人,在不同的时间,不同车程使用该函数来计算本次的费用
double getTaxiPrice(int hours,int distance)
{
double totalPrice = 0.0; //定义打车费用
double perPrice = 2.3; //定义每公里单价计费
int startPrice = 13; //定义起步价
///1.时间相关
if(hours<0 || hours>24){
printf("请填写正确的时间n");
return 0;
}
else if(!(hours>=5 && hours<23)) //判断打车时间是否要增加费用
{
perPrice *= 1.2; //费用增加20%
}

/////////2.距离相关 
if(distance<=0)
{
    return 0;
}
else if(distance >3) //判断公里数
{
    totalPrice = startPrice +(distance - 3)*perPrice;   //计算价钱
}
else
{
    totalPrice = startPrice; /////////////////   
}

//////
totalPrice++;   //加一块钱的燃油费
return totalPrice;////////消费的乘车计费 

}
int main()
{
int moring = 9; //定义上午打车时间
int afternoon = 3; //定义下午打车时间
int distance = 27; //定义打车公里数
double totalPrice = 0; //定义总费用
////////测试一下不同时间,不同距离,可能非法的时间或距离;

if(getTaxiPrice(moring,distance) != 0)
{
    totalPrice = getTaxiPrice(moring,distance); //调用计算费用的函数
}
else if(totalPrice != 0)
{
    totalPrice += getTaxiPrice(afternoon,distance); //调用计算费用的函数
}
printf("小明每天打车的总费用是:%.2fn",totalPrice);    //输出
return 0;    

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/233610.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号