|
I couldn't tell you. The first thing I would look for is an InnerException in the exception that you get.
|
|
|
|
|
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
|
|
|
|
|
Stepping through your code while debugging might give you an idea on what this code is doing.
|
|
|
|
|
I'm not going to look at that - it's a code dump, and pretty much unreadable without formatting.
So start like this: edit your question, cut it down to just the relevant bits, and enclose them in <pre> tags, by highlighting it, and using the "code" widget on the toolbar above the textbox.
That will keep the indentation and engage the syntax highlighter, which makes it a lot easier for us to read. It changes this:
// 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,");
}
}
To this:
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,");
}
} which is much, much easier to follow - especially when it is part of a larger context.
Then, drop the homework question at the top, and tell use what you expect the code to do and what it is doing that you didn't expect, or not doing that you did - and how you get it to do that. Remember, we can't see your screen!
Then we might be able to help you more easily - help us to help you!
The only instant messaging I do involves my middle finger.
|
|
|
|
|
Okay, so here's what I understand about Destructors…
They are mainly used to help clear up any resources with unmanaged i.e. code, streams, certain type of events etc.
I also understand you put it inside your class at the very bottom preceded with a tilde, same name as the class… No modifiers of any kind.
Here is where I'm a little confused; in the example's I was given… It has just this and nothing else:
~MyClass
{
}
Will it work "good enough", without adding any "destruction statements"?
Or…
Should I be entering some statements to make sure it's taken care of?
|
|
|
|
|
You do know this is a C++ question, not a C# one, right?
But to answer the question, it's OK to have an empty destructor if you don't have any resources to clean up.
In fact, if your class definition lacks a destructor of any kind, the compiler generates one for you which does nothing.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
it is not a C++ question!
|
|
|
|
|
I apologize for my ignorance.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Not exactly true...
Read this[^]
|
|
|
|
|
Well I'll be a monkey's uncle!
Thank you for correcting me.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If you are its uncle, I'm its cousin twice removed.
TIL the c++ destructor syntax is valid in c#
|
|
|
|
|
"Empty destructors should not be used. When a class contains a destructor, an entry is created in the Finalize queue. When the destructor is called, the garbage collector is invoked to process the queue. If the destructor is empty, this just causes a needless loss of performance." - http://msdn.microsoft.com/en-us/library/66x5fx1b.aspx
TY!
|
|
|
|
|
Destructors are not magic and do not automatically clean up your resources by just putting the placeholder code there. If you allocate unmanaged objects YOU must un-allocate them.
However, I would advise reading up on the differences between using a destructor versus implementing IDisposable. Destructors in C# are very different than those in C++ and understanding when they are called and what they do is important in how you effectively use them.
See this StackOverflow answer[^] on using IDisposable and finalizers.
Note how the proper use of IDisposable helps you since you, the programmer, have almost no control when the finalizers are run, and absolutely no control about what order they run in (finalizers for unreferenced objects are not guaranteed to run in any particular order, and this could be important).
|
|
|
|
|
To be fair if you do not know how to use correctly create and use IDisposable then it will be just a bad as a destructor.
|
|
|
|
|
In general, you should not need to add destructors to your code.
You can explore the Dispose method.
|
|
|
|
|
WidmarkRob wrote: I also understand you put it inside your class at the very bottom preceded with a tilde, same name as the class… No modifiers of any kind. It doesn't have to go at the bottom. In C#, the way you order your methods has no effect on the way your code performs at run time.
In general, I'm not a big fan of finalizers. Finalize objects are treated differently to objects without finalizers, even if you dispose of the object and call GC.SuppressFinalizer() . Have a read about the freachable queue here[^].
|
|
|
|
|
I disabled Lazy Loading for various reasons (Mostly proxy craziness and performance) but I have hit a snag I don't know how to handle.
I have an address table that has a street address broken into parts. One of the pieces is a SuffixId that determines if it is a street, ave, etc... Here is my fullAddress property of the address:
public string fullAddress
{
get
{
string address = number.ToString();
if (direction != null)
address += " " + direction;
address += " " + street;
if (suffixId != null)
address += " " + StreetSuffix.abbreviation;
return address;
}
}
Now my problem is with the StreetSuffix.abbreviation part, I am getting a null reference. How do I handle this?
Cheers, --EA
|
|
|
|
|
Why are number, direction and street also notnull. Because you load the information somewhere. I suspect you are not loading the StreetPrefix record.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
As usual, you are correct. Forgot to include the StreetSuffix in the Get.
Cheers, --EA
|
|
|
|
|
My client has asked me to incorporate text messaging into an app I'm working on. I've never done this before.
1) Do I need to set something up on their server?
2) What's the code look like for this? I've been Googling but found a lot of different samples.
Can someone point me in the right direction?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
A lot depends on what you are doing, at a basic level you'll need an SMS service. If you are doing bulk SMS work you'll need to google SMS providers and find ones that provide an API, I found results googling "sms api" though that'd take a fair bit of digging to get the best deal based on your usuage.
If you need something lower-end, some phones act like modems when connected via USB and provide the functionality google "send sms from my phone connected to pc" and you'll get some joy. It looks like Android plays with this sort of thing really well.
I've not done this sort of work, but I have seen both the above in operation.
|
|
|
|
|
Hello,
How can I use WM_PASTE to send a plain text from clipboard to the active window and the focused textbox/combobox ?
----------
I want to paste by double-Click, I can detect the double click event and execute a code when it done
so the destination window will be active the textbox/combobox will be focused
please provide me a little sample project working with a timer in background and do the paste command.
I keep searching for a solution to this problem for days but no results
-------------------
Thanks
JusT LeT YouR MinD WorK
|
|
|
|
|
WM_PASTE is the message sent to the Window in which Paste operation takes place.
Refer: Link[^]
|
|
|
|
|
I understand this
all what I need is a simple example to know how to do it
JusT LeT YouR MinD WorK
|
|
|
|
|
This message must be handled by the receiving window. When you receive a WM_PASTE [^] message, it is your responsibility to deal with it. You should generally read the contents of the clipboard and past them onto your window, or wherever else your program wishes.
Veni, vidi, abiit domum
|
|
|
|
|