Calculate an energy bill from meter readings to display on a smart meter.
★★★With the invention of the dynamo in 1861, electrical energy could be generated in large amounts. The first mass application of electricity was lighting. When this new product – electrical energy – started to be sold, it was obvious that the cost had to be determined. The earliest meter was Samual Gardiner’s (USA) lamphour meter patented in 1872. It measured the time during which energy was supplied to the load, as all the lamps connected to this meter were controlled by one switch. Subdividing lighting circuits became practical with the introduction of Edison’s light bulb, and this meter became obsolete.
Write a program that calculates the cost of energy from a previous and current meter reading. The kilowatt hours is the total units_used between the two readings multiplied by 1.022 multiplied by the calorific_value divided by 3.6. The cost in pounds sterling is 0.0284 multiplied by kilowatt hours.
Remember to add a comment before a subprogram to explain its purpose.
energy_cost that:previous_meter_reading, current_meter_reading and calorific_value.Enter the previous meter reading:
2022
Enter the current meter reading rounded down:
2305
Cost is £ 89
Enter the previous meter reading:
7666
Enter the current meter reading rounded down:
8241
Cost is £ 182
// Energy bill calculator program
using System;
class Submission
{
---
// -------------------------
// Subprograms
// -------------------------
// Calculate the energy bill
---
static int energy_cost(int previous_meter_reading, int current_meter_reading, double calorific_value)
{
---
int units_used = current_meter_reading - previous_meter_reading;
double kwh = units_used * 1.022 * (calorific_value / 3.6);
---
double cost = 0.0284 * kwh;
---
return (int)cost;
---
}
---
// -------------------------
// Main program
// -------------------------
public static void Main(string[] args)
{
---
Console.WriteLine("Enter the previous meter reading:");
int previous_meter_reading = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the current meter reading rounded down:");
int current_meter_reading = Convert.ToInt32(Console.ReadLine());
double calorific_value = 39.3;
---
int cost = energy_cost(previous_meter_reading, current_meter_reading, calorific_value);
---
Console.WriteLine("Cost is £ " + cost);
---
}
---
}