Given the number of electrical units consumed the task is to calculate and display the total amount payable. Follow the below given cost chart.
- First 1 to 50 units 2 ₹/unit
- Next 51 to 100 units 4 ₹/unit
- Next 101 to 150 units 6 ₹/unit
- More than 150 units 8 ₹/unit
C
#include <stdio.h>
int main()
{
int u=0,charge=0;
printf("Enter the consumed units: ");
scanf("%d",&u);
if(u>0&&u<=50)
{
charge=(u-0)*2;
}
else if(u>50&&u<=150)
{
charge=((50-0)*2)+((u-50)*4);
}
else if(u>150&&u<=300)
{
charge=((50-0)*2)+((150-50)*4)+((u-150)*6);
}
else if(u>300)
{
charge=((50-0)*2)+((150-50)*4)+((300-150)*8)+((u-300)*8);
}
else
{
printf("Number of units cannot be zero or negative");
}
printf("Payable Amount: Rs %d",charge);
return 0;
}C