Segmentation calculation residents water bills
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
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int x;
double y;
Scanner reader =new Scanner(System.in);
x=reader.nextInt();
if(x<15)
y=4*x/3.0;
else
y=(float) (2.5*x-17.5);
System.out.printf("%.2f",y);
}
}
c language
#include<stdio.h>
int main()
{
int x;
double y;
scanf("%d",&x);
if(x<15)
y=4*x/3;
else
y=2.5*x-17.5;
printf("%.2f",y);
return 0;
}