鱼C论坛

 找回密码
 立即注册
查看: 4353|回复: 4

【求教育】 甲鱼老师的那个运费的问题谁还记得

[复制链接]
发表于 2012-1-27 20:01:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
过年了 没什么好送的
回帖有奖 每人1鱼币
少了点但代表心意
【原题如下】
作业(2)
运输公司对用户的计费
路程(s)越远,每公里的用费越低,具体标准如下:
s<250km ;            没有折扣;     250<=s<=500;     2%的折扣;
s<=500<1000;     5%的折扣;    1000<=s<2000 ;   8%的折扣;
2000<=s<3000;   10%的折扣;   3000<=s;           15%的折扣;
设每公里货物的基本运费为p,货物重为w,距离为s,折扣为d,则总运费的计算公式为:
f = p*w*s*(1 - d)
#include<stdio.h>
void main()
{
double f,p,w,s,d;
printf("请输入基本运费,货物总重,距离");
scanf("%lf%lf%lf",&p,&w,&s);
if (s<250)
{
  d = 0;
}
if(s>=250&&s<500)
{
  d = 0.02;
}
if(s>=500&&s<=1000)
{
  d = 0.05;
}
if(s>=1000&&s<2000)
{
  d = 0.08;
}
if(s>=2000&&s<3000)
{
  d = 0.10;
}
if(s>=3000)
{
  d = 0.25;
}
printf("总运费=%lf",p*w*s*(1-d));
}
老师说用switch语句但是我没有用纯粹的if套下来的
不知道对不对 还有今天的播布客也抽筋
死活上不去  甚至115都和我较劲;
顺便说下这个编译通过了的
小甲鱼最新课程 -> https://ilovefishc.com
 楼主| 发表于 2012-1-27 20:01:28 | 显示全部楼层
嘿嘿沙发归我
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-1-27 20:15:42 | 显示全部楼层

回帖奖励 +20 鱼币

没有20.你就惨了
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-1-27 21:53:14 | 显示全部楼层
贴个我写的,一起学习
  1. #include <stdio.h>

  2. double discount( int s );
  3. double total( double p, double w, double s );
  4. int main(){       
  5.         double p,w,s;
  6.         printf("请输入基本运费,货物总重,距离");
  7.         scanf("%lf%lf%lf",&p,&w,&s);
  8.         printf("总运费=%lf\n",total(p,w,s));
  9.         return 0;
  10. }

  11. double discount( int s ) {
  12.         static double data[]={ 0.0, 0.02, 0.05, 0.05, 0.08, 0.08, 0.08, 0.08, 0.1, 0.1, 0.1, 0.1, 0.15 };
  13.         if ( s>3000 ) s = 3000;
  14.         return data[s/250];
  15. }

  16. double total( double p, double w, double s ) {
  17.         return p*w*s*(1-discount(s));
  18. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-3-21 16:09:56 | 显示全部楼层
对我来说还是有点难,主要是没有编程思想
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-11 00:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表