Write a program in C# Sharp to calculate and print the Electricity bill of a given customer. The customer id., name and unit consumed by the user should be taken from the keyboard and display the total amount to pay to the customer. The charge are as follow :
Unit Charge/unit
upto 199 @1.20
200 and above but less than 400 @1.50
400 and above but less than 600 @1.80
600 and above @2.00
If bill exceeds Rs. 400 then a surcharge of 15% will be charged and the minimum bill should be of Rs. 100/-
Test Data :
1001
James
800
Expected Output :
Customer IDNO :1001
Customer Name :James
unit Consumed :800
Amount Charges @Rs. 2.00 per unit : 1600.00
Surchage Amount : 240.00
Net Amount Paid By the Customer : 1840.00
using System;
using System.IO;
using System.Collections.Generic;
namespace App
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.Write("Enter the customer id: ");
      int id = int.Parse(Console.ReadLine());
      Console.Write("Enter the customer name: ");
      string name = Console.ReadLine();
      Console.Write("Enter the unit consumed by the customer: ");
      int units = int.Parse(Console.ReadLine());
      float amountCharges = 0;
      float perUnit = 0;
      //upto 199 @1.20
      if (units < 200)
      {
        perUnit = 1.20f;
        amountCharges = units * perUnit;
      }
      //200 and above but less than 400 @1.50
      if (units >= 200 && units < 400)
      {
        perUnit = 1.50f;
        amountCharges = units * perUnit;
      }
      //400 and above but less than 600 @1.80
      if (units >= 400 && units < 600)
      {
        perUnit = 1.80f;
        amountCharges = units * perUnit;
      }
      //600 and above @2.00
      if (units >= 600)
      {
        perUnit = 2.00f;
        amountCharges = units * perUnit;
      }
      //If bill exceeds Rs. 400 then a surcharge of 15% will be charged and the minimum bill should be of Rs. 100/-
      float surcharge=0;
      if (amountCharges >= 400) {
        surcharge = amountCharges * 15.0f / 100.0f;
      }
      float netAmount = amountCharges + surcharge;
      if (netAmount < 100) {
        netAmount = 100;
      }
      Â
      Console.WriteLine("Customer IDNO: {0}", id);
      Console.WriteLine("Customer Name: {0}", name);
      Console.WriteLine("Unit Consumed: {0}", units);
      Console.WriteLine("Amount Charges @Rs.{0:N2} per unit: {1:N2}", perUnit, amountCharges);
      Console.WriteLine("Surchage Amount: {0:N2}", surcharge);
      Console.WriteLine("Net Amount Paid By the Customer: {0:N2}",netAmount);
      Console.ReadLine();
    }
  }
}
Comments
Leave a comment