Write a C program to input electricity unit charges and calculate total electricity bill by using the switch statement according to the given condition:
For the first 50 units Rs. 0.50/unit
For the next 100 units Rs. 0.75/unit
For the next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill.
Flowchart of the program to calculate the total electricity bill by using the switch statement
C++ Source Code to calculate the total electricity bill switch statement
#include<iostream>
using namespace std;
int main()
{
int unit;
float amount,total_amount,s_charge;
cout<<"enter the number of units you consumed"<<endl;
cin>>unit;
switch(unit<=50)
{
case 1:
amount=unit*0.50;
break;
case 0:
switch(unit<=150)
{
case 1:
amount=25+(unit-50)*0.75;
break;
case 0:
switch(unit<=250)
{
case 1:
amount=100+(unit-150)*1.20 ;
break;
case 0:
amount=220+(unit-250)*1.50;
break;
}
break;
}
break;
}
s_charge=amount*0.20;
total_amount=amount+s_charge;
cout<<"your total bill is Rs"<<total_amount;
}
Output
enter the number of units you consumed
100
your total bill is Rs 75
SFT (Shamil’s Flow Table )
Are you interested to Read about SFT(Shamil’s Flow Table)?

