Please refer to this picture for clear Electric Block usage
The output should be 102.80 when I insert the number of 350kWh but mine output appear RM 180.600006 and the decimal places too long, I have been put %2f but still appear long decimal. Here the output. The electric consumption will be divided into blocks.
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#include <stdio.h>
//For the first 200 kWh (1-200 kWh) per month = RM21.80
//For the next 100 kWh (201-300 kWh) per month = RM33.40
//For the next 300 kWh (301-600 kWh) per month = RM51.60
//For the next 300 kWh (601-900 kWh) per month = RM54.60
//For the next kWh (901 kWh onwards) per month = RM57.10
int main()
{
float Electric_Consumption, Bill;
printf("Please insert the Current Electric Consumption: ");
scanf("%f", &Electric_Consumption);
if (Electric_Consumption >=1 && Electric_Consumption <= 200)
{
Bill = (Electric_Consumption*(21.80/100));
printf("Your bill need to pay is RM %f", Bill);
}
else if(Electric_Consumption >=201 && Electric_Consumption <= 300)
{
Bill = (Electric_Consumption*(33.40/100));
printf("Your bill need to pay is RM %f", Bill);
}
else if(Electric_Consumption >=301 && Electric_Consumption <= 600)
{
Bill = (Electric_Consumption*(51.60/100));
printf("Your bill need to pay is RM %f", Bill);
}
else if(Electric_Consumption >=601 && Electric_Consumption <= 900)
{
Bill = (Electric_Consumption*(54.60/100));
printf("Your bill need to pay is RM %f", Bill);
}
else if(Electric_Consumption >=900)
{
Bill = (Electric_Consumption*(57.10/100));
printf("Your bill need to pay is RM %f", Bill);
}
else
{ printf("You inputed wrong electric consumption!");
}
return 0;
}