一定要考虑重量为整数的时候,这个写着写着就遗忘了
#include<iostream> #include<iomanip> using namespace std; int main() { float weight; int weight1,price,extraprice; char cha; cin>>weight>>cha; weight1=weight; if(cha=='y') { if(weight!=weight1&&weight>0) { cout<<int(weight1)+25; } else cout<<int(weight1-1)+25; } if(cha=='n') { if(weight!=weight1&&weight>0) { cout<<int(weight1)+20; } else cout<<int(weight1-1)+20; } return 0; }