Home C C++ Java Python Perl PHP SQL JavaScript Linux Online Test Forum

Home » Forum » x-Forum » Question

What is the problem in this program ?

Write a C program to input electricity unit charges and calculate total electricity bill according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For 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.

According to this question, i made the program using if else statement.Please tell me what is wrong in this program in order to get the required answer.


#include <stdio.h>

int main()
{
  float unit,price,total,tax;
  printf("enter the EEelectricity units");
  scanf("%d", &unit);

  if (unit <=50)
    price=0.50*unit;
  else if (unit>50 && unit<=150)
    price=25+0.75*unit;
   else if (unit>150 && unit<=250)
    price=100+1.2*unit;
   else
    price=220+1.50*unit;

  tax=0.2*price;
  total=tax+price;



  printf("so the final bill is %.2f", &total);


   return 0;
}

Posted by neeraj019 2019-04-24 03:32:06

/* Hi neeraj019, here is the correct program. Let us  know if you need anything else */

#include <stdio.h>

int main()
{
  float unit,price,total,tax;
  printf("Enter the Electricity units : ");
  scanf("%f", &unit);

  if (unit <=50)
    price=0.50*unit;
  else if(unit>50 && unit<=150)
    price=25+ (0.75*(unit-50));
   else if (unit>150 && unit<=250)
    price=25 + 75 + (1.2* (unit - 150));
   else
    price=25+ 75 + 120 + (1.50* (unit-250));

  printf("
 Before Tax : %.2f ", price);
  tax=0.2*price;
  total=tax+price;

  printf("
 After tax, final bill is %.2f", total);

   return 0;
}

C++ user image Admin posted 2019-04-24 12:37:02

Please login to comment

Log In


Ask New Question