Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim intCalories As Integer Dim intFat As Integer Dim intPercent As Integer intCalories = CInt(txtCalories.Text) intFat = CInt(txtFat.Text) intPercent = intFat * 9 / intCalories lblPercent.Text = intPercent.ToString("n2") End Sub End Class
The fat percentage will be shown in a label once it is calculated. The book tells us that calories from fat = fat grams * 9 and percentage of calories from fat = calories from fat / total calories. The user will enter the amount of calories and fat in the food. Is this a mathematical error that I am just not catching from looking at this for too long or am I making a code mistake.
Also - the percentage of fat should have a % sign in the label. I've tried the ("p") for the last line of code however learned that when you do that the program multiplies the numbers, which is not what I want, I just want the % symbol. I cannot find anything in my book about how to achieve this. I put a % sign in the label and made the visibility false but that didn't work.
I am very new to all of this and have been steadily getting the hang of it which is why this is frustrating because it should be somewhat simple!
Thank you so much!