Question

C#

3. Write a program to calculate and print the Electricity bill of a given customer. Read the units consumed by the user from

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class ElectricityBillCalculation
{
public static void Main(string[] args)
{
  
int units = Convert.ToInt16(Console.ReadLine()); // Reading the units consumed from the console
double a,b,c,d,e; // Initialising variables
int p,q,r,s; // Initialising variables
Console.WriteLine("Enter the units consumed by the customer :{0}", units); // Printing units consumed by the customer
if (units <= 200) // If condition to check if units consumed are less than or equal to 200
{ // Enters if condition is satisfied
a = (units * 1.5); // Bill calculation using Mul operator
Console.WriteLine("Total amount to pay ={0}", a); // Printing electricity bill to be pais by customer

}
else if (units >= 201 && units <= 400) // If condition to check if units >= 201 and <=400
{ // Enters if condition is satisfied
p = units - 200; // Storing how many units consumed above 200
b = (p * 1.8) + 300; // Bill calculation using Mul operator for units >200 and <=400, adding bill for 400 units
Console.WriteLine("Total amount to pay ={0}", b); // Printing electricity bill to be pais by customer

}
else if (units >= 401 && units <= 600) // If condition to check if units >= 401 and <=600
{ // Enters if condition is satisfied
q = units - 400; // Storing how many units consumed above 400
c = (q * 2.1) + 300 + 360; // Bill calculation using Mul operator for units greater than 400 and adding bill for 400 units
Console.WriteLine("Total amount to pay ={0}", c); // Printing electricity bill to be pais by customer
}
else if (units >= 601 && units <= 800) // If condition to check if units >= 601 and <=800
{ // Enters if condition is satisfied
r = units - 600; // Storing how many units consumed above 600
d = (r * 2.5) + 300 + 360 + 420; // Bill calculation using Mul operator for units greater than 600 and adding bill for 600 units
Console.WriteLine("Total amount to pay ={0}", d); // Printing electricity bill to be pais by customer
}
else if (units > 800) // If condition to check if units >800
{ // Enters if condition is satisfied
s = units - 800; // Storing how many units consumed above 800
e = (s * 2.7) + 300 + 360 + 420 + 500; // Bill calculation using Mul operator for units greater than 800 and adding bill for 800 units
Console.WriteLine("Total amount to pay ={0}", e); // Printing electricity bill to be pais by customer
}

Console.ReadKey();
}
}

main.cs 1. using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 public class Elect

Add a comment
Know the answer?
Add Answer to:
C# 3. Write a program to calculate and print the Electricity bill of a given customer....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The utility department of Brentwood City needs you to write a C++ program that will print...

    The utility department of Brentwood City needs you to write a C++ program that will print out a customer's bill. The program should input the following items from the file named "utility.txt" (which you may copy from the class data share or Blackboard): The customer number (6-digit integer) The number of gallons of water used (floating-point, no more than 999.99) The number of kilowatts of electricity used (integer, no more than 999) The number of cubic feet of natural gas...

  • Write a program that will calculate and print bills for the city power company. The rates...

    Write a program that will calculate and print bills for the city power company. The rates are computed as follows: $60 flat fee for the first 1000 kwh and $0.05 for each additional kwh used. Your program should prompt the user to enter the consumption of kwh (in integer) and display the total amount of charge (use %.2f for the display). Sample Test 1: Enter kwh used: 945 Your total charge is $60.00 Sample Test 2: Enter kwh used: 1100...

  • Need help with this please Lab 14 Electricity Bill Worksheet Background knowledge. The power of an...

    Need help with this please Lab 14 Electricity Bill Worksheet Background knowledge. The power of an electrical appliance is measured in watt (W). One watt is a measure of the energy used up in one second. The unit used for calculating power consumption is the kilowatt-hour (kWh). In order to calculate power consumed by an electrical appliance, we first convert the power to kilowatt (kW). For example, 800 W=0.8 kW, 2000 W = 2.0 kW and so on. One unit...

  • computer programming Write a C program that will calculate and print monthly water bills. The total...

    computer programming Write a C program that will calculate and print monthly water bills. The total units consumed per month are derived from subtracting the previous meter readings with the current meter reading. The charges are calculated based on the rates stated in Table 2. The sample output is shown in Figure 16 Tulis aturcara Cyang akan mengira dan mencetak bil air bulanan Jumlah unit yang diguna sebulan dikira dengan menolak bacaan meter sebelum dengan bacaan meter terkinl. Caj dikira...

  • Write a C program that will calculate the gross pay of a set of employees. The...

    Write a C program that will calculate the gross pay of a set of employees. The program should prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below. The program determines the overtime hours (anything over 40 hours), the gross pay and then outputs a table in the following format. Column alignment, leading zeros in Clock#, and zero suppression in float fields is important. Use 1.5 as the overtime pay...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • Please include function in this program Write a C program that will calculate the gross pay...

    Please include function in this program Write a C program that will calculate the gross pay of a set of employees utilizing pointers instead of array references. You program should continue to use all the features from past homeworks (functions, structures, constants, strings). The program should prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below. The program determines the overtime hours (anything over 40 hours), the gross pay and...

  • Coding in C++ Write a program using structures to store the following weather information: - Month...

    Coding in C++ Write a program using structures to store the following weather information: - Month name - Day of month (Monday, Tuesday, etc) - High Temperature - Low Temperature - Rainfall for the day Use an the input.txt file to load the data into weather structures. Once the data for all the days is entered, the program should calculate and display the: - Total rainfall for the data - Average daily temperatures. (note: you'll need to calculate the days...

  • Question 2 (3 mark): Write a program to implement the class Coffee according to the following...

    Question 2 (3 mark): Write a program to implement the class Coffee according to the following UML diagram and description so that it can display as the output example. Coffee -energy: double -protein: double -fat: double +Coffee +Coffee _energy: double, _protein: double. _fat: double) Coffee(sourceCup: Coffee) -printNutrition Information(): void +main(String[] args): void REQUIREMENTS The program has three constructors: the first one is a default constructor, it initializes the 3 data fields (50.0, 1.5, 1.7) at default; the second initializes the...

  • c++ programming no use of classes use of functions pseudo code with comments Requirement: Provide one...

    c++ programming no use of classes use of functions pseudo code with comments Requirement: Provide one application for a business store that sale 2 models of one proo model FA218 and model FA318. The application first provides the menu to allow users can select one of the following tasks per time and when they finish one task, they can continue the application to select other task from the menu until they choose exit. All the output on the screen and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT