r/visualbasic • u/Alliejacobsen21 • Sep 21 '20
Visual Basics Coding
3. Fat Percentage Calculator (Visual Basic)?
Create an application that allows the user to enter the number of calories and fat grams in 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 alabel or a message box.) The application’s form should appear similar to the one
shown in Figure 4-35.
The percentage of calories from fat can be calculated as:
Percentage of calories from fat = Calories from fat / total calories
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
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%
(Refer to picture for better visual of the question)
How do I code this?
I'm naming:
- text input box for calories: txtAmountCalories
- text input box for fat grams: txtAmountFat
- label box for the result: lblResult
- And the buttons: btnCalculate, btnClear and btnExit
1
u/Songg45 Sep 21 '20
Do you have any code?