Energy Charge- units consumed (rate/100) Energy Charge 700*,14-S98 Total Bill En
ID: 3756793 • Letter: E
Question
Energy Charge- units consumed (rate/100) Energy Charge 700*,14-S98 Total Bill Energy Charge+Connection Charge Total Bill- 98+90-$188 Develop a program in C that will input units consumed for the previous month and will calculate and display the bill for that particular connection as shown in the sample output below To begin, read a connection type from the user: 1 for Residential, 2 for Commercial and 3 for Industrial. Assume that the user can enter an invalid input multiple times, so, prompt an appropriate error message until a valid connection is chosen. This error check is shown in the sample output below. Next, read units consumed for that connection, again, perform an error check. A unit is invalid if it is negative (less than zero). Here, again assume that the user can provide an invalid input for unit's multiple times. Using the connection type, units consumed and the rate from the table below calculate the total bill for Electricity for the user (using the formula above). Make sure the program loops and asks if the user wants to continue to calculate another Bill. If the user hits 1 the calculator should start again for a new bill, if the user hits 0 the program should terminate by showing the proper output (It should show how many times the bill was calculated and what is the grand total of all the bills) Implement the bonus after this. Your results should match the sample output below, Use formatting to print the dollar amount correct Commercial Upper Ratein Lower Upper Rate(in Bound cents) Bound Bound cents) Bound Bound cents) 700 13.50 2000 17.50 2000 00045.50 bove Functions to implement: NOTE: Use of global variables will result in a 30-point deduction. I. void displayMenuO 2. int errorCheck(int option): 3. int errerCheckUnits(int units); Prints the display options Error checking inputs for displayMenu). Returns a 0 if invalid, and 1 is the input is valid Error checking for valid unit inputs. If unit input is less than 0, return 0. If valid, return 1Explanation / Answer
#include<stdio.h>
#include<conio.h>
void displayMenu();
int errorCheck(int option);
int errorCheckUnits(int units);
void main(){
int count=0;
double totalBill=0;
while(1){
count++;
int option;
double energyCharge;
double connectionCharge;
double currentBill;
displayMenu();
scanf("%d",&option);
if(errorCheck(option))
{
int units;
while(1){
printf("Enter the number of units(in kWh): ");
scanf("%d",&units);
if(errorCheckUnits(units))
{
break;
}
}
switch(option){
case 1:
if(units>=0&&units<=200)
{
energyCharge = (units*7.5)/100;
}
else if(units>200&&units<=700)
{
energyCharge = (units*10)/100;
}
else if(units>700&&units<=1250)
{
energyCharge = (units*13.50)/100;
}
else if(units>1250)
{
energyCharge = (units*15)/100;
}
connectionCharge = 25;
currentBill = energyCharge + connectionCharge;
totalBill = totalBill+ currentBill;
break;
case 2:
if(units>=0&&units<=300)
{
energyCharge = (units*10.5)/100;
}
else if(units>300&&units<=1000)
{
energyCharge = (units*14)/100;
}
else if(units>1000&&units<=2000)
{
energyCharge = (units*17.50)/100;
}
else if(units>2000)
{
energyCharge = (units*20)/100;
}
connectionCharge = 90;
currentBill = energyCharge + connectionCharge;
totalBill = totalBill+ currentBill;
break;
case 3:
if(units>=0&&units<=500)
{
energyCharge = (units*36.5)/100;
}
else if(units>500&&units<=2000)
{
energyCharge = (units*40)/100;
}
else if(units>2000&&units<=3000)
{
energyCharge = (units*45.50)/100;
}
else if(units>3000)
{
energyCharge = (units*50)/100;
}
connectionCharge = 850;
currentBill = energyCharge + connectionCharge;
totalBill = totalBill+ currentBill;
break;
}
printf("Total energy charge for this customer is:$ %.2f ",energyCharge);
printf("Connection charge for this customer is:$ %.2f ",connectionCharge);
printf("Total bill due from this connection is:$ %.2f ",currentBill);
printf("Do you want to continue and calculate another bill? if Yes enter 1, else 0:");
int continueK;
scanf("%d",continueK);
if(continueK==0)
{
break;
}
}
}
printf("You calculated the bill %d times and the total amount from all of the bill due is $%.2f",count,totalBill);
}
void displayMenu(){
printf("1. Residential 2. Commercial 3. Industrial Choose the type of connection:");
}
int errorCheck(int option){
if(option==1||option==2||option==3)
return 1;
printf("Invalid Choice! Please enter a valid choice ");
return 0;
}
int errorCheckUnits(int units){
if(units>=0)
return 1;
printf("Invalid input! ");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.