You are on page 1of 8

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

C Projects

Submitted By:

Submitted To:

VAIBHAV JAIN HCL TRAINER ECE/09/152


1|Page

INDEX
TOPIC OBJECTIVE DESCRIPTION o No. of variables used with their data types and range o Looping constructs used o Decision making statements used CODING OUTPUT WINDOW P.NO. 3 4

6 8

HCL PROJECT

Page 2

OBJECTIVE
AN ELECTRICITY BILL CALCULATOR

HCL PROJECT

Page 3

DESCRIPTION
Description of variables---S. Variables No used 1 ch, ch1 . Data- Range type int signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 +/- 3.4e +/- 38 (~7 digits) Size 4 bytes Its use in program to input the numeral

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

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

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 n when 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

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

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

OUTPUT WINDOW

HCL PROJECT

Page 8

You might also like