3. Fat Percent Calculator (Page 302 – 303) Fat Percentage Calculator Create an application that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. (Display the message in a label or a message box.) The application’s form should appear similar to the one shown in Figure 4-35. One gram of fat has 9 calories, so: Calories from fat = fat grams * 9 The percentage of calories from fat can be calculated as: Percentage of calories from fat = Calories from fat / total calories

ON Bookmark Show all steps: Chapter 4, Problem 3PC Fat Percentage Calculator Horml Chapter 1 txtTotalc Label1 Eoter the nuabe

Input validation: Make sure the number of calories and fat grams are numeric, and are not less than 0. Also, the number of calories from fat cannot be greater than the total number of calories. If that happens, display an error message indicating that either the calories or fat grams were incorrectly entered. Use the following test data to determine if the application is calculating properly: Calories and Fat Percentage Fat 200 calories, 8 fat grams Percentage of calories from fat: 36% 150 calories, 2 fat grams Percentage of calories from fat: 12% (a low-fat food) 500 calories, 30 fat grams Percentage of calories from fat: 54%

this is what I have but its not working

Public Class Form1
    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim totalCalories As Decimal
        Dim fatgrams As Decimal
        Dim Caloriesfromfat As Decimal
        Dim PercentageofCaloriesFromfat As Decimal
        lblDisp.Text = “”
        If Not Integer.TryParse(txtTotalCalories.Text, CInt(totalCalories)) Or Not
                Integer.TryParse(txtFatGrams.Text, CInt(fatgrams)) Then
    MessageBox.Show(“The number of calories and fat grams are not numeric.”)
        ElseIf totalCalories
            MessageBox.Show(“The number of calories and fat grams are not less than 0.”)
        ElseIf fatgrams > totalCalories Then
            MessageBox.Show(“Number of Fat grams cannot be greater”)
        Else
            Caloriesfromfat = 9 * fatgrams
            PercentageofCaloriesFromfat = (Caloriesfromfat)
            lblDisp.Text = FormatPercent(PercentageofCaloriesFromfat)
            If PercentageofCaloriesFromfat * 100
                MessageBox.Show(“a low-fat food”)
            End If
        End If

    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtTotalCalories.Clear()
        txtFatGrams.Clear()
        lblDisp.Text = “”
    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()

    End Sub

    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click

    End Sub
End Class

ON Bookmark Show all steps: Chapter 4, Problem 3PC Fat Percentage Calculator Horml Chapter 1 txtTotalc Label1 Eoter the nuaber of calories in the food Chapter 2 alories Chapter 3 Label2 Feter the number of fet arams in the food txtFatGrams Chapter 4 Label3, lblDisp Percentnge of celoies t come from fat T 1AW btnclea Clear Ext btnExit Calculate btnCalc 1FB 1FF Apply the property values as shown below the tabular form: 1MC Common Controls Value Property Text 1PC Forml Fat Percentage 1SA Calculator Label1 Enter the number Text 1TF bdories in the food: 1WDT Label2 Text Enter the number 2AW t grams in 2EF the food: Percentage of calories that come from fat: txtTotalCalories txtFatGrams Label3 Text 2MC 2PC TextBoxl Name 25A ТextBox2 Labe14 Name 1blDisp btncalc Calculate btnclear Name 2TF Buttonl Name 2WDT Теxt Button2 Name Clear Text Button3 Name btnExit Теxt Exit



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *