package lianXiTi;
import java.util.Scanner;
public class Shi_er02 {
public static void main(String[] args) {
System.out.println("请输入行李的重量:");
Scanner sc=new Scanner(System.in);
int weight=sc.nextInt();
double total=0;
if(weight<=50) {
total=weight*0.15;
}
else {
total=50*0.15+(weight-50)*0.22;
}
System.out.println("总计:"+total);
}
}
#include <iostream.h>
#include <iomanip.h>
void main()
{
double weight,fee;
char c='n';
do{
cout<<"请输入托运行李重量: ";
cin>>weight;
if(weight<0)
{
cout<<"重量不能小于0 !"<<endl;
continue;
}
if(weight>50)
fee = 50 * 0.15 + ( weight - 50 ) * 0.22;
else
fee = weight * 0.15;
cout<<"托运费为 :";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<fee<<endl;
cout<<"继续计算?(y/n) :";
cin>>c;
}while(c=='y'||c=='Y');
}