Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: datatable . help needed Pin
Andy_L_J1-Oct-13 22:20
Andy_L_J1-Oct-13 22:20 
QuestionExternal component has thrown an exception Pin
Member 102708251-Oct-13 18:13
Member 102708251-Oct-13 18:13 
AnswerRe: External component has thrown an exception Pin
Abhinav S1-Oct-13 20:44
Abhinav S1-Oct-13 20:44 
GeneralRe: External component has thrown an exception Pin
Member 102708252-Oct-13 0:38
Member 102708252-Oct-13 0:38 
GeneralRe: External component has thrown an exception Pin
Dave Kreskowiak2-Oct-13 4:37
mveDave Kreskowiak2-Oct-13 4:37 
GeneralRe: External component has thrown an exception Pin
ramonminarro11-Mar-22 3:10
ramonminarro11-Mar-22 3:10 
GeneralRe: External component has thrown an exception Pin
Dave Kreskowiak11-Mar-22 3:46
mveDave Kreskowiak11-Mar-22 3:46 
QuestionC# assignment please help Pin
bmulgrew11-Oct-13 18:07
professionalbmulgrew11-Oct-13 18:07 
Hi all

im trying to do a assignment for programing and i cant get my program to do give me the output as described below


Program description:
Develop a program to implement a billing system for an electricity supply company. The billing program will gather information about each customer’s name, customer number, address, whether they are on Standard rates or Peak/Off Peak rates, and how much electricity they have consumed. Once all customer details have been entered it will allow electricity consumption data to be entered for all customers. It will then allow the bill for all customers to be calculated (including a 10% Goods and Service Tax) and display the results. It will also calculate and display the average energy usage per customer and the average bill per customer.

The program is required to hold data for up a maximum of 50 customers. Note, however, that this number may be revised in the future so your program should allow for this to be easily re-coded.

The program must operate via a menu system. The menu to control the program should be as follows:

Add a Customer Record (a)
Find a Customer Record (f)
Update a Customer Record (u)
Enter Electricity Consumption data (e)
Calculate Bills (b)
Clear Consumption data (c)
Exit (x)
The program must display the menu and wait for the user’s response and process the options entered until the user enters 'x' to quit. Menu option entries may be in upper or lower case. Use a switch statement to organise the code to suit the option selected.

Details of the menu options are as follows:

Add a customer record:

Prompt the user for the customer number, customer’s name, address and whether they are on standard rates or Peak/Off Peak rates and then store the entered data into the next array position.

All of these fields are compulsory and so must not be left blank.

Find a customer record:

Prompt for the name of the customer to search for.

· The user may enter all or part of the name.
· Search through all of the customer names until a match is found and return the customer number of the person found.
· Display the customer record found, including details of electricity consumption.

Update a Customer Record:

First perform a find (see above) to display the required record and then display the fields one at a time, each time asking the user if they wish to enter a new value or not. For example:

Customer name > Freddie Krueger
Update this information (Y or N)> Y
Enter new customer name > Frederick Krueger

Enter Electricity Consumption data:

This option will list ALL customers, one at a time, each time prompting the user to enter the electricity consumption data for that customer. If the customer is on Peak/Off Peak rates then the system will prompt separately for both Peak electricity consumption and Off Peak consumption, otherwise it will prompt only for total electricity consumption.

Calculate Bills:

This option will list ALL customers, one at a time, each time displaying the customer details and the bill as calculated based on consumption data that has been entered. The calculation of the bill is based on the following:

· Consumption at the Standard Rate is billed at $0.32 per Kilowatt Hour.
· Consumption at the Peak Rate is billed $0.50 per Kilowatt Hour.
· Consumption at the Off Peak Rate is billed at $0.18 per Kilowatt Hour.
· After calculating the amount of the bill a Goods and Services Tax of 10% is then added to the bill.

Once all customers’ bills have been processed the average bill per customer and the average electricity consumption per customer (in Kilowatt Hours) should be calculated and displayed.

Note: This option should only be accessible after electricity consumption data has been entered.

Clear Consumption data:

This option will go through all customer records and reset the electricity usage data to 0 in preparation for entering new data for the next billing period. Note that all other customer details must remain unaltered in this process.

Here's my code

// start of code
using System;

namespace ass1
{
class Bill
{
// Display menu and get response
static char get_menu()
{
char response;
Console.WriteLine("Add a Customer Record (a)");
Console.WriteLine("Find a Customer Record (f)");
Console.WriteLine("Update a Customer Record (u)");
Console.WriteLine("Enter Electricity Consumption data (e)");
Console.WriteLine("Calculate Bills (b)");
Console.WriteLine("Clear Consumption data (c)");
Console.WriteLine("Exit (x)");
response = char.Parse(Console.ReadLine());

return response;

}
// Find a Cusotmer Number based on giving the customer number
static int Customer_no(string[] records, int current_count, int CustomerNumbers_entered)
{
string find_data = "";
int item = 0;
bool found = false;
Console.Write("Customer Number: > ");
find_data = Console.ReadLine();
for (item = 0; item < CustomerNumbers_entered; item++)
{
if (records[item] == find_data)
{
current_count = item;
found = true;
break;
}
}
if (found == false)
Console.WriteLine("No Customer Information found");
else
Console.WriteLine("Customer Information found");
return current_count;
}

static float get_float(string prompt, float min)
{
string vtemp = "";

while (Attempt == false)
{




}
}

static void Main(string[] args)
{
// Declare and initialise variables and constants
// Constants
const int MAX_Cusomter = 50;

// Variables
const float PEEK_RATE = 0.50F;
const float OFF_PEAK_RATE = 0.18F;
const float STANDARD_RATE = 0.32F;
const float GST_RATE = 0.10F;
const string PEAK_SYM = "P";
const string STANDARD_SYM = "S";

// Customer variables

string[] Customer_no;
Customer_no = new string[MAX_Cusomter];

string[] CustomerNumber;
CustomerNumber = new string[MAX_Cusomter];

string[] CustomerName;
CustomerName = new string[MAX_Cusomter];

string[] Address;
Address = new string[MAX_Cusomter];

string[] RateType;
RateType = new string[MAX_Cusomter];

float PeakKWH = 0.0F;
float OffPeakKWH = 0.0F;
float TotalStandardPeakKWH = 0.0F;


// Ttrack the total and averages
float TotalBilled = 0.0F;
float TotalUsage = 0.0F;
float AverageBilled = 0.0F;
float AverageUsage = 0.0F;

// Count the number of valid customers
int CustomerCount = 0;

// Calculation variables

float PeakCharge = 0.0F;
float OffPeakCharge = 0.0F;
float TotalCharge = 0.0F;
float TotalPlusGST = 0.0F;

int current_count = 0;
int number_of_customers = 0;

//Temp variables
string inputStr = "";
bool parseAttempt = false;
char response = ' ';

while (response != 'x')
{

response = get_menu();


switch (response)
{
case 'a':
// Initialise
// INPUT
// Set the variable defaults
CustomerNumber[current_count] = "";
CustomerName[current_count] = "";
Address[current_count] = "";
RateType[current_count] = "";
PeakKWH = 0.0F;
OffPeakKWH = 0.0F;
TotalStandardPeakKWH = 0.0F;

// Get the Customer Number and exit is an error is detected

break;

case 'f':
// Find a cutomer Recored
current_count = find_data(records, current_count, CustomerNumbers_entered);
break;

case 'u':
// Update a customer recorded
if (CustomerNumber[Customer_no] == "")
{
Console.WriteLine("Update Info for new Customer >");
Customer_no [CustomerNumber] = Console.ReadLine();
if (Customer_no[CustomerNumber] == "")
{
Console.WriteLine("Error : Customer Number cannot be empty,");
}

// Get the Customer Name and exit is an error is detected
while (CustomerNumber[Customer_no] == "")
{
Console.Write("Customer Name > ");
CustomerName[Customer_no] = Console.ReadLine();
if (CustomerNumber[Customer_no] == "")
{
Console.WriteLine("Error : Customer Name cannot be empty,");
}
}
// Get the Customer Address and exit is an error is detected
while (Address[Customer_no] == "")
{
Console.Write("Address > ");
Address[Customer_no] = Console.ReadLine();
if (Address[Customer_no] == "")
{
Console.WriteLine("Error : Address cannot be empty,");
}
}

}

break;

case 'e':

// Get the Rate Type and exit is an error is detected
while (RateType[Customer_no] != PEAK_SYM && RateType[Customer_no] != STANDARD_SYM)
{
Console.Write("Standard Rate (S) or Peak/Off Peak (P) >");
RateType[Customer_no] = Console.ReadLine().ToUpper();
if (RateType[Customer_no] != PEAK_SYM && RateType[Customer_no] != STANDARD_SYM)
{
Console.WriteLine("Error : The Rate Type must be either S or P.");
}
}
// If Rate Type is P prompt for the usage
if (RateType[Customer_no] == PEAK_SYM)
{
parseAttempt = false;
while (parseAttempt == false)
{
// Peak Usage data
Console.Write("Peak Usage (kWh) > ");
inputStr = Console.ReadLine();
parseAttempt = float.TryParse(inputStr, out PeakKWH);
// Ensure the value entered is a valid numeric value
if (parseAttempt == false)
{
Console.WriteLine("Error : Peak Usage must be a valid numeric value.");
parseAttempt = false;
}
// Ensure the value entered is > 0
if (PeakKWH < 0)
{
Console.WriteLine("Error : Peak Usage must be a valid numeric value greater than or equal to 0.");
parseAttempt = false;
}
}

parseAttempt = false;
while (parseAttempt == false)
{
Console.Write("Off Peak Usage (kWh) > ");
inputStr = Console.ReadLine();
parseAttempt = float.TryParse(inputStr, out OffPeakKWH);
// Ensure the value entered is a valid numeric value
if (parseAttempt == false)
{
Console.WriteLine("Error : Off Peak Usage must be a valid numeric value.");
parseAttempt = false;
}
// Ensure the value entered is > 0
if (OffPeakKWH < 0)
{
Console.WriteLine("Error : Off Peak Usage must be a valid numeric value greater than or equal to 0.");
parseAttempt = false;
}
}
}
else // If Rate Type is S prompt for the usage
{
parseAttempt = false;
while (parseAttempt == false)
{
// Standard Usage data
Console.Write("Total Usage (kWh) > ");
inputStr = Console.ReadLine();
parseAttempt = float.TryParse(inputStr, out TotalStandardPeakKWH);
// Ensure the value entered is a valid numeric value
if (parseAttempt == false)
{
Console.WriteLine("Error : Total Usage must be a valid numeric value.");
parseAttempt = false;
}
// Ensure the value entered is > 0
if (TotalStandardPeakKWH < 0)
{
Console.WriteLine("Error : Total Usage must be a valid numeric value greater than or equal to 0.");
parseAttempt = false;
}
}
}

break;
case 'b':
// PROCESS the calculations
if (TotalCharge == 0)
{
Console.Write("Warrning need no Cutomer in the System");
inputStr = Console.ReadLine();
}
else
if (RateType[current_count] == PEAK_SYM)
{
PeakCharge = PeakKWH * PEEK_RATE;
OffPeakCharge = OffPeakKWH * OFF_PEAK_RATE;
TotalCharge = PeakCharge + OffPeakCharge;
// Keep track of the usage
TotalUsage = TotalUsage + (PeakKWH + OffPeakKWH);
}
else
{
TotalCharge = TotalStandardPeakKWH * STANDARD_RATE;
// Keep track of the usage
TotalUsage = TotalUsage + TotalStandardPeakKWH;
}

TotalPlusGST = TotalCharge + TotalCharge * GST_RATE;
// Keep track of the total billed
TotalBilled = TotalBilled + TotalPlusGST;

// Ad 1 to the customer count
Customer_no = CustomerNumber + 1;

// Calculate the averages only if the count is > 0
if (CustomerNumber > 0)
{
AverageBilled = TotalBilled / CustomerNumber[current_count];
AverageUsage = TotalUsage / CustomerNumber[current_count];
// Display the averages
Console.WriteLine("Average amount billed is {0:C}.", AverageBilled);
Console.WriteLine("Average consumption per customer is {0:C}.", AverageUsage);
}
else
Console.WriteLine("No Customer data entered.");
Console.ReadLine();

// OUTPUT the customer information and bill
Console.WriteLine("===================================");
Console.WriteLine("Electricity Bill for Customer {0}", CustomerNumber);
Console.WriteLine("===================================");
Console.WriteLine("Name : {0}", CustomerName);
Console.WriteLine("Address : {0}", Address);
if (RateType[current_count] == PEAK_SYM)
{
Console.WriteLine("Peak : {0,7:C}", PeakCharge);
Console.WriteLine("Off Peak : {0,7:C}", OffPeakCharge);
}

Console.WriteLine("Total : {0,7:C}", TotalCharge);
Console.WriteLine();
Console.WriteLine("Including GST : {0,7:C}", TotalPlusGST);
Console.WriteLine("===================================");
// End While
Console.WriteLine();


break;

case 'c':
// Initialise
PeakCharge = 0.0F;
OffPeakCharge = 0.0F;
TotalCharge = 0.0F;
TotalPlusGST = 0.0F;
TotalBilled = 0.0F;
TotalUsage = 0.0F;
AverageBilled = 0.0F;
AverageUsage = 0.0F;
break;
case 'x':
break;
default:
Console.WriteLine("Unknown menu selection");
break;
}


}
}
}
}
//end of code
I am very confused with the code and i'm not sure what i'm doing wrong,i'm not to be able to display what i need as a output.

Any help or suggestions are greatly appreciated.

Regards Brendan
AnswerRe: C# assignment please help Pin
Abhinav S1-Oct-13 21:10
Abhinav S1-Oct-13 21:10 
AnswerRe: C# assignment please help Pin
OriginalGriff1-Oct-13 21:25
mveOriginalGriff1-Oct-13 21:25 
GeneralDestructors Pin
N8tiv1-Oct-13 15:34
N8tiv1-Oct-13 15:34 
GeneralRe: Destructors Pin
Richard Andrew x641-Oct-13 16:29
professionalRichard Andrew x641-Oct-13 16:29 
GeneralRe: Destructors Pin
N8tiv1-Oct-13 16:31
N8tiv1-Oct-13 16:31 
GeneralRe: Destructors Pin
Richard Andrew x641-Oct-13 17:09
professionalRichard Andrew x641-Oct-13 17:09 
GeneralRe: Destructors Pin
Dave Kreskowiak1-Oct-13 17:05
mveDave Kreskowiak1-Oct-13 17:05 
GeneralRe: Destructors Pin
Richard Andrew x641-Oct-13 17:08
professionalRichard Andrew x641-Oct-13 17:08 
GeneralRe: Destructors Pin
Keith Barrow1-Oct-13 22:45
professionalKeith Barrow1-Oct-13 22:45 
GeneralRe: Destructors Pin
N8tiv1-Oct-13 19:56
N8tiv1-Oct-13 19:56 
AnswerRe: Destructors Pin
Ron Beyer1-Oct-13 17:48
professionalRon Beyer1-Oct-13 17:48 
GeneralRe: Destructors Pin
jschell2-Oct-13 8:42
jschell2-Oct-13 8:42 
AnswerRe: Destructors Pin
Abhinav S1-Oct-13 21:12
Abhinav S1-Oct-13 21:12 
GeneralRe: Destructors Pin
Pete O'Hanlon1-Oct-13 21:58
mvePete O'Hanlon1-Oct-13 21:58 
QuestionEager Loading Problem Pin
eddieangel1-Oct-13 11:53
eddieangel1-Oct-13 11:53 
AnswerRe: Eager Loading Problem Pin
Mycroft Holmes1-Oct-13 12:54
professionalMycroft Holmes1-Oct-13 12:54 
GeneralRe: Eager Loading Problem Pin
eddieangel1-Oct-13 13:06
eddieangel1-Oct-13 13:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.