Write a program that calculate the cost of energy for energy units restricted between 0 to 500 kWh for an amount less than $6 000.00 for any Zimbabwean resident customer and any amount and unlimited number of units for a foreign resident customer buying from outside Zimbabwe at a rate of $90.00 to one USD. The tariffs are as follows:
• 0 to 50 kWh cost $2.25
• Above 50 kWh to 100 kWh cost $4.51 / kWh
• Above 100kWh to 200 kWh cost $7.89 / kWh
• Above 200kWh to 300 kWh cost $11.25 / kWh
• Above 300kWh to 400 kWh cost $12.94 / kWh
• Above 400 kWh cost $13.50 / kWh
#include <stdio.h>
double determineEnergyCost(double units)
{
if(units > 0 && units <= 50)
return 2.25;
if(units > 50 && units <= 100)
return 4.51;
if(units > 100 && units <= 200)
return 7.89;
if(units > 200 && units <= 300)
return 11.25;
if(units > 300 && units <= 400)
return 12.94;
return 13.5;
}
int main()
{
printf("Are you Zimbabwean resident customer?[y/n]");
char answer;
scanf(" %c", &answer);
double units;
printf("\nunits = ");
scanf("%lf", &units);
if(answer == 'y')
{
if(units <= 500)
{
double energyCost = determineEnergyCost(units);
double cost = energyCost * units;
if (cost <= 6000)
printf("Cost: %g$", cost);
else
printf("Sorry, but your amount is more than 6000$");
}
else
printf("Sorry, but you can't buy more than 500kWh");
}
else
{
double energyCost = determineEnergyCost(units);
double cost = energyCost * units;
printf("Cost: %g$", cost);
}
printf("\n\n");
return 0;
}
Comments
Leave a comment