Reputation: 984
Basically I would like the user to input 3 values into a textbox and have a button that calculates the total of the 3 inputted values. I thought I could read the user input and then convert it into an integer and from that apply a formula to work out fnum+snum+tnum = total; What I have done so far does not work can anybody guide me thanks.
int num1 = int.Parse(weighting1.Text);
int num2 = int.Parse(weighting2.Text);
int num3 = int.Parse(weighting3.Text);
total = num1+num2+num3;
int total = int.parse(lTotal.Text);
// Code to display the variable
Upvotes: 0
Views: 143
Reputation: 223237
instead of int.parse(lTotal.Text) you need to assign total's string value to label
lTotal.Text = total.ToSTring();
Your code should be:
int num1 = int.Parse(weighting1.Text);
int num2 = int.Parse(weighting2.Text);
int num3 = int.Parse(weighting3.Text);
int total = num1+num2+num3;
lTotal.Text = total.ToSTring();
Upvotes: 2
Reputation: 150108
If I understand correctly, lTotal
is your label and you want to put the value of total
into the Text of the label? If so:
lTotal.Text = total.ToString()
Your current code goes in the other direction... it reads whatever is currently the Text of the Label lTotal, attempts to parse that text as an integer, and assigns it to total. You also redeclare total in that line (int total
, whereas you use total
in the preceding line) which should not compile.
Upvotes: 0