electricity bill calculator

11
S.B.I.T. & HCL Infosys ltd. C Projects 1 | Page

Upload: vaibhav-jain

Post on 28-Nov-2014

137 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Electricity Bill Calculator

S.B.I.T. & HCL Infosys ltd.

C Projects

Submitted By: Submitted To:VAIBHAV JAIN HCL TRAINERECE/09/152

1 | P a g e

Page 2: Electricity Bill Calculator

INDEXTOPIC P.NO.

OBJECTIVE 3 DESCRIPTION 4

o No. of variables used with their data types and range

o Looping constructs used

o Decision making statements used

CODING 6 OUTPUT WINDOW 8

HCL PROJECT Page 2

Page 3: Electricity Bill Calculator

OBJECTIVE

AN ELECTRICITY BILL CALCULATOR

HCL PROJECT Page 3

Page 4: Electricity Bill Calculator

DESCRIPTIONDescription of variables----

S. No

Variables used

Data-type

Range Size Its use in program

1.ch, ch1 int signed: -2147483648 to 2147483647unsigned: 0 to 4294967295

4 bytes to input the

numeral

2.puc1, puc2, puc3, amnt, total, unt, num

float +/- 3.4e +/- 38 (~7 digits)

4 bytes to input and

output the numeral

in decimals

Looping Constructs Used----

While---

Here in this program while loop is used to check the condition on *s mean the loop will go till the value of *s reaches null

HCL PROJECT Page 4

Page 5: Electricity Bill Calculator

A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement. The while construct consists of a block of code and a condition. The condition is evaluated, and if the condition is true, the code within the block is executed. This repeats until the condition becomes false. Because while loops check the condition before the block is executed, the control structure is often also known as a pre-test loop. Compare with the do while loop, which tests the condition after the loop has executed.

Decision Making statement used----

if—

In this program if statement is used to check the condition on nwhen an interpreter finds an If, it expects a boolean condition - for example, x > 0, which means “the variable x contains a number that is greater than zero” - and evaluates that condition. If the condition is true, the statements following the Then are executed. Otherwise, the execution continues in the following branch - either in the Else block (which is usually optional), or if there is no Else branch, then after the End If.

HCL PROJECT Page 5

Page 6: Electricity Bill Calculator

CODING#include<stdio.h>#include<conio.h>float chrgs(float num, float puc1, float puc2, float puc3);float tax(float num);void main(){int ch,ch1;float puc1,puc2,puc3;float unt;float total,amnt;clrscr();printf("ELECTRICITY BILL CALCULATOR...\n");printf("This is the program to calculate your electricity bill as per your unit usage\n");printf("In this program 1st u have to enter the per unit charge for the electricity\nfor 1st 200 units\n then for the 2nd 200 units\n n then for the rest of the units\nby default the value of tax is taken to be 7.5%");printf("\n\n\nNow enter 1 to calculate your bill or any other integer to exit\n");scanf("%d",&ch);if(ch==1){printf("\nNow enter the per unit charge for 1st 200 units:\t");scanf("%f",&puc1);printf("\nNow enter the per unit charge for 2nd 200 units:\t");scanf("%f",&puc2);printf("\nNow enter the per unit charge for remaining units:\t");scanf("%f",&puc3);printf("\nNow enter your total unit usage");scanf("%f",&unt);amnt= chrgs(unt,puc1,puc2,puc3);printf("\n\nyour total charges for the used units is Rs.%f ", amnt);printf("\n\n Your total tax will be Rs.%f",tax(amnt));total=amnt+tax(amnt);printf("\n\nTotal payable amount is Rs.%f",total);printf(“\n\n\nNow to continue with different value of unit usage type 1\n\t\t\tOR\nType any other integer to exit”);scanf(“%d”,&ch1);while(ch1==1){printf("\nNow enter another value of unit usage");scanf("%f",&unt);

HCL PROJECT Page 6

Page 7: Electricity Bill Calculator

amnt= chrgs(unt,puc1,puc2,puc3);printf("\n\nyour total charges for the used units is Rs.%f ", amnt);printf("\n\n Your total tax will be Rs.%f",tax(amnt));total=amnt+tax(amnt);printf("\n\nTotal payable amount is Rs.%f",total);printf("\n\n\nNow to continue with different value of unit usage type 1\n\t\t\tOR\nType any other integer to exit");scanf(“%d”,&ch1);}}printf("\n \n \n This program was made by Mr. VAIBHAV JAIN");printf("\n Thank you for spending your precious time in using it");printf("\n have a nice day. Good bye!!!! :-)");getch();}float chrgs(float num, float puc1, float puc2, float puc3){float amnt=0.0;if(num<200){amnt=(puc1*num);}if(num>200 && num<400){num=num-200;amnt=(puc1*200)+(puc2*num);}if(num>400){num=num-400;amnt=(puc1*200)+(puc2*200)+(puc3*num);}return(amnt);}float tax(float num){return((num*7.5)/100);}

HCL PROJECT Page 7

Page 8: Electricity Bill Calculator

OUTPUT WINDOW

HCL PROJECT Page 8