electricity board charges in C

electricity board charges in C

18CPL17/27 


Program 5:- 

An electricity board charges the following rates for the use of electricity: for the first 200 units 80 paCSE per unit: for the next 100 units 90 paCSE per unit: beyond 300 units Rs 1 per unit. All users are charged a minimum of Rs. 100 as meter charge. If the total amount is more than Rs 400, then an additional surcharge of 15% of the total amount is charged. Write a program to read the name of the user, the number of units consumed and print out the charges.

ALGORITHM 

PURPOSE: Read The Name Of The User, Number Of Units Consumed And Print
INPUT: name [10], unit
OUTPUT: Print the charges for the total number of units consumed

START

STEP 1: [Input a name and units]
read name and unit

STEP 2: [Initialization]
Metercharge=100

STEP3: [To check electricity unit is less than or equal to 200 and calculate metercharge] If unit less than or equal to 200
metercharge= metercharge+(unit*.80)

STEP 4: [Else check unit is greater than 200 and greater than 300 and calculate metercharge] If unit greater than 200 and unit greater than or equal to 300
metercharge= metercharge+(200*0.80)+((unit-200)*0.90)) STEP 5: [Else check unit is greater than 300 and calculate metercharge]
If unit is greater than 300
metercharge= metercharge+(200*0.80)+(300*0.90)+((unit-300)*1))

STEP 6: [To check and calculate if the meter charge is greater than 400 ]
If meter charge greater than or equal to 400
metercharge=metercharge+(metercharge*0.15);

STEP 7: [Finished]

STOP

FLOW CHART



C Code



****************************************
 Output 1:
 Enter your name and unit Consumed:Suresh 200
 Name: Suresh
 Number of unit consumed: 200
 MeterCharge : 260.000


Output 2:
 Enter your name and unit Consumed:Ramesh 400
 Name: Ramesh
 Number of unit consumed: 400
 MeterCharge : 724.5000


******************************************************************************
 Viva Questions:

1) What is else-if ladder?
The else-if ladder statement executes one condition from multiple statements. The execution starts from the top and checked for each if condition. The statement of if block will be executed which evaluates to be true. If none of the if the condition evaluates to be true then the last else block is evaluated.

2) What are the possible outputs of if statement?
Possible outputs of if the statement is Either True or False.

3) What is a conditional branching statement?
Based on the condition when the flow of the program starts branching is known as conditional branching.
ex:- if,if-else,if-else-if etc

4) Write the syntax of if- statement?
if (condition)
{   
//code
}

5) Write the syntax of else if statement?
if(condition)
    {
      // code if condition is true
    }
    else
    {
      // code if condition is false
    } 

No comments:

For Query and doubts!

Powered by Blogger.