Writing a pretty simple cost calculator, and everything is coming out right except the total of everything. Why is the total for everything displaying placeholders instead of numbers, and how can I fix it? I really appreciate any input, thanks!
public partial class Form1 : Form
private void label2_Click(object sender, EventArgs e)
private void calculaterevenueButtonrm_Click(object sender, EventArgs e)
// Declaring for user inputed ticket totals
classatickets = decimal.Parse(classaTextBoxrm.Text);
classbtickets = decimal.Parse(classbTextBoxrm.Text);
classctickets = decimal.Parse(classcTextBoxrm.Text);
// Storing the cost of each ticket class
decimal classacost = 15;
decimal classbcost = 12;
decimal classccost = 9;
//Declaring names for the results of each class's calculations and how to calculate them
classatotal = classatickets * classacost;
classbtotal = classbtickets * classbcost;
classctotal = classctickets * classccost;
classarevenueTextBoxrm.Text = classatotal.ToString("c");
classbrevenueTextBoxrm.Text = classbtotal.ToString("c");
classcrevenueTextBoxrm.Text = classctotal.ToString("c");
// Define how to calculate the total sales
totalsales = classatotal + classbtotal + classctotal;
totalrevenueTextBoxrm.Text = totalsales.ToString("c");
catch (Exception ex)
//default error message
private void clearButtonrm_Click(object sender, EventArgs e)
classaTextBoxrm.Text = "";
classbTextBoxrm.Text = "";
classcTextBoxrm.Text = "";
classarevenueTextBoxrm.Text = "";
classbrevenueTextBoxrm.Text = "";
classcrevenueTextBoxrm.Text = "";
totalrevenueTextBoxrm.Text = "";
Thanks for the reply Arjay. I thought I had taken a shot of the output after debugging. I am just selecting "debug" and then "start debugging." This is what happens when I debug(no errors). I input 1 for each field.
[I think I know what is the problem, but since I started to explain how to debug, I'm going to continue]
What debugging allows you to do is to watch the program variables while your program executes. It also allows you to step through each line of code and makes sure variables are getting set as you expect and other logic is working as intended.
So starting by pressing F5 (debug program) is a good start, but to be really useful, you'll need to set one or more breakpoint so the program will stop so you can inspect the variables.
To do this, set a breakpoint at the following line inside the calculaterevenue...click handler:
Just put the mouse over the line above, click and then press F9. You'll notice a little circle appears to the left of the line of code.
Next, press F5 to start debugging. Enter the values and click the calculate button.
You'll notice the program will stop on the break point. To inspect a variable, hold the mouse over the classatickets variable. You should see that the value is the same as what you entered. Next, hold the mouse over the classbtickets variable. You should see either null or "" as the value. This is because this line of code hasn't executed yet.
Press F10 to execute the next line of code to inspect more variables or press F5 to continue running the program (and hit additional breakpoints if any).
Okay, so that's a quick debugging primer, now onto your problem.
I suspect the problem is the style of the Totals text box has been set to Password = true. To check this, open the forms editor, right click on the totals text box and choose properties. Then make sure that the Password entry is set to false.