Discussion need help with C programming issue

Oct 25, 2021
5
0
10
0
Write a program to calculate the water rates according to the table below:
An example of the output interface :

This program calculates the monthly water bill for you.
Please key in the water consumption for this month (in m^3): -10
Wrong! Can’t be negative value! Key in again!
Please key in the water consumption for this month (in m^3): 10
You need to pay for RM 2.50 for this month
Thanks for using my program.
Press any key to continue...

Minimum ChargeRM2.50 per month
First 20,000 litresRM0.22 per 1,000 litres
More than 20,000 litres to 40,000 litresRM0.46 per 1,000 litres
More than 40,000 litres to 60,000 litresRM0.68 per 1,000 litres
More than 60,000 litres to 200,000 litresRM1.17 per 1,000 litres
More than 200,000 litresRM1.30 per 1,000 litres


#include <stdio.h>

float cur_meter, min_charge1=2.50,total1,total2,total3,total4,total5;

int main()
{
printf("This program calculates the monthly water bill for you.\n");
printf("Please key in the water consumption for this month (in m^3) \n");
scanf("%f", &cur_meter);


if(cur_meter==0){
printf("You need to pay for RM%f for this month\n", min_charge1); /no issue for displaying this/
}

if(cur_meter>0 && cur_meter<=20000){ /the output starts to get weird starting here total1 until total5/
total1=(cur_meter/1000)*0.22;
printf(" You need to pay for RM%f for this month\n", total1);

}
else if(cur_meter>20000 && cur_meter<=40000){
total2=total1+((cur_meter-20000)*0.46);
printf(" You need to pay for RM%f for this month\n", total2);

}
else if(cur_meter>40000 && cur_meter<=60000){
total3=total1+total2+((cur_meter-40000)*0.68);
printf(" You need to pay for RM%f for this month\n", total3);

}
else if(cur_meter>60000 && cur_meter<=200000){
total4=total1+total2+total3+((cur_meter-60000)*1.17);
printf(" You need to pay for RM%f for this month\n", total4);

}
else if(cur_meter>200000){
total5=total1+total2+total3+total4+((cur_meter-200000)*1.30);
printf(" You need to pay for RM%f for this month\n", total5);

}

while(cur_meter<0){ /no issue for displaying this as well/
printf("Wrong! Can’t be negative value! Key in again! \n");
printf("Please key in the water consumption for this month (in m^3) \n");
scanf("%f", &cur_meter);
}
}

The outputs are big ridiculous number -.-.... can someone kindly help me to look at this. C programming
 
Thread starter Similar threads Forum Replies Date
aymen9309 Apps General Discussion 1
SyndiShanX Apps General Discussion 1
D Apps General Discussion 1
BlueMoon1890 Apps General Discussion 0
Neon The (Anthro) Umbreon Apps General Discussion 1
K Apps General Discussion 2
T Apps General Discussion 10
M Apps General Discussion 2
R Apps General Discussion 3
S Apps General Discussion 2
N Apps General Discussion 1
P Apps General Discussion 4
A Apps General Discussion 8
M Apps General Discussion 6
D Apps General Discussion 1
MEMOFLEX Apps General Discussion 1
S Apps General Discussion 16
M Apps General Discussion 3
JonnyDough Apps General Discussion 7
G Apps General Discussion 1

ASK THE COMMUNITY