Program:
/* To enter consumer number, name, present month reading, last month reading. Calculate and display total units and bill amount by the following table
Rate/Unit | Units |
---|---|
1.45(min) | 0 - 5 |
2.80 | 51 - 100 |
3.05 | 101 - 200 |
4.75 | 201 - 300 |
5.50 | >300 |
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
long int cno;
int pmr, lmr, tunits;
char cname[20];
float bamt;
clrscr();
printf("Enter Consumer Number :");
scanf("%ld", &cno);
printf("Enter Consumer Name :");
fflush(stdin);
gets(cname);
printf("Enter present month reading :");
scanf("%d", &pmr);
printf("Enter Last Month Reading :");
scanf("%d", &lmr);
if (pmr < lmr)
{
printf("Invalid Reading");
getch();
exit(0);
}
tunits = pmr - lmr;
if (tunits<=50)
if (tunits<=50)
bamt = tunits * (float)1.45;
else if (tunits<=100)
bamt = ( 50 * (float) 1.45 ) + ( (tunits-50) *(float)2.80 ) ;
else if (tunits<=200)
bamt = ( 50 * (float) 1.45 ) + ( 50 * (float) 2.80 ) + ( (tunits-100) *(float)3.05 ) ;
else if (tunits<=200)
bamt = ( 50 * (float) 1.45 ) + ( 50 * (float) 2.80 ) + ( 100 * (float) 3.05 ) + ( (tunits-200) *(float)4.75 ) ;
else if (tunits<=200)
bamt = ( 50 * (float) 1.45 ) + ( 50 * (float) 2.80 ) + ( 100 * (float) 3.05 ) + ( 100 * (float) 4.75 )+( (tunits-300) *(float)5.50 ) ;
clrscr();
printf("\nConsumer Number is : %ld", cno);
printf("\nConsumer Name is : %s", cname);
printf("\nPresent Month Reading is : %d", pmr);
printf("\nLast Month Reading is : %d", lmr);
printf("\nTotal Units is : %d", tunits);
printf("\nTotal Bill Amount is : %.2f", bamt);
getch();
}
Output:
Enter Consumer Number is : 1412108010
Enter Consumer Name is : Tirupathi
Enter Present Month Reading : 22499
Enter Last Month Reading : 22000
Consumer Number is : 1412108010
Consumer Name is : Tirupathi
Present Month Reading : 22499
Last Month Reading : 22000
Total Units is : 499
Total Bill Amount is : 2087.00
Next Topic :
Previous Topic :
No comments:
Post a Comment