多语言展示
当前在线:1870今日阅读:100今日分享:18

C++程序代码解析:[3]运输问题

运费:p.重量:w.距离:s.折扣:d. S<250KM       没有折扣250<=S<500      2%折扣1000<=S<1000    5%折扣2000<=S<2000    8%折扣2000<=S<3000    10%折扣3000<=S         15%折扣
工具/原料
1

C++

2

程序

方法/步骤
1

总运费公式:f=p*w*s*(1-d/100)

2

#include 'PRO.h'//程序目录的相对路径中的头文件.#include //输入输出头文件.

3

using namespace std;//命名空间输入输出标准,不同的命名空间可以有相同的类名被定义

4

int main()//主函数

5

int c,s;float p,w,d,f;//定义变量.

6

cout <<'please enter p,w,s:';//输出语句.cin >>p >>w >>s;//输入语句

7

if(s>=3000)//复合语句c=12;elsec=s/250;

8

switch(c)//switch语句{case 0:d=0;break;case 1:d=2;break;case 2:case 3:d=5;break;case 4:case 5:case 6:case 7:d=8;break;case 8:case 9:case 10:case 11:d=10;break;case 12:d=15;break;}

10

程序代码如下:

11

程序运行如下:

推荐信息