蒟蒻求助

B2088 计算书费

the_traveler @ 2023-07-26 10:56:04

#include<bits/stdc++.h>

using namespace std;

double a,s;

int main(){

    for(int i=1;i<=10;i++){
        cin>>a;
        if(i==1)s+=28.9*a;
        if(i==2)s+=32.7*a;
        if(i==3)s+=45.6*a;
        if(i==4)s+=78*a;
        if(i==5)s+=35*a;
        if(i==6)s+=86.2*a;
        if(i==7)s+=27.8*a;
        if(i==8)s+=43*a;
        if(i==9)s+=56*a;
        if(i==10)s+=65*a;
    }
    cout<<s;

   return 0;

   }

by SiXinchen @ 2023-07-26 11:00:19

s要保留一位小数


by SiXinchen @ 2023-07-26 11:03:21

推荐使用printf

printf("%.1lf",s);

by Starry_dream @ 2023-07-26 11:09:23

如果用cout就要用setprecision+fixed; 具体用法:

cout<<fixed<<setprecision(1)<<s;

by pengruowei @ 2023-08-21 20:48:44

保留一位小数呀


|