[PTA] 7-23 segment OFSETTLEMENT water (10 minutes)

To encourage residents to save water, water companies take measures according to water usage pricing ladder, the residents water bills payable y (yuan) monthly water consumption associated with x (t): when x is not more than 15 t, y = 4x / 3 ; after over, y = 2.5x-17.5. Please write a program to achieve the calculation of water charges.

Input format:
input given nonnegative real number x in a row.

Output format:
the water line of output payable, accurate to 2 decimal places.

Input Example 1:
12 is

Output Sample 1:
16.00

Input Sample 2:
16

Output Sample 2:
22.50

#include <stdio.h>
int main()
{
    double x,y;
    scanf("%lf",&x);
    if (x<=15)
    {
        y=4*x/3;
    }
    else
    y=2.5*x-17.5;
    printf("%.2lf",y);

    return 0;
}
Published 48 original articles · won praise 0 · Views 320

Guess you like

Origin blog.csdn.net/weixin_46399138/article/details/105368771