I am having a problem with my static casting. I keep getting only one response no matter what values I use in the program. It's as the bottom half of my program is not executing. I cannot figure out what I am doing incorrectly. I am sure it is obvious, but after looking for two days I don't see it.
/*Program: CL8_Zick_UrsulaAuthor: Ursula ZickDate: 02/13/2019Purpose: Calculate the percentage of calories from fat*/
#include#includeusing namespace std;int main(){// Variantsint fatGrams; // Total number of calories in one gram of fatint fatCalories; // Total amount of calories from fatint totalCalories; // Total number of calories from fatint fatPercentage; // Total fat percentage from caloriescout < "enter="" the="" requested="" information="" to="" determine="" the="" percentage="" of="" fat="" in="" food="" item;="">// Get the total calories from food itemcout < "enter="" the="" total="" calories:="">cin >> totalCalories;// Get the total fat grams from food itemcout < "enter="" the="" total="" fat="" grams:="">cin >> fatGrams;// Convert the fat calories to fat gramsfatCalories = fatGrams * 9;// Determine if fat gram is less than zeroif (totalCalories < 0="" ||="" fatgrams=""><>cout < "="" total="" calories="" or="" fat="" grams="" can="" not="" be="" less="" than="" zero="">else{if (fatCalories > totalCalories)cout < "\ninvalid="" -="" there="" are="" more="" calories="" in="" fatgrams="">< "grams="" of="" fat="" than="" you="" entered="" for="" total="" calories:="">}// Static cast on the fat percentagefatPercentage = static_cast (fatCalories) / totalCalories;// Calculate fat percentageif (fatPercentage *= 100)cout < "percentage="" of="" fat:="">else{if (fatPercentage <>cout < "\nthat="" food="" is="" low="" in="" fat:="">elsecout < "\nthat="" food="" is="" not="" low="" in="">}return 0;}
int main(){// Variantsint fatGrams; // Total number of calories in one gram of fatint fatCalories; // Total amount of calories from fatint totalCalories; // Total number of calories from fatint fatPercentage; // Total fat percentage from calories
cout < "enter="" the="" requested="" information="" to="" determine="" the="" percentage="" of="" fat="" in="" food="" item;="">
// Get the total calories from food itemcout < "enter="" the="" total="" calories:="">cin >> totalCalories;
// Get the total fat grams from food itemcout < "enter="" the="" total="" fat="" grams:="">cin >> fatGrams;
// Convert the fat calories to fat gramsfatCalories = fatGrams * 9;// Determine if fat gram is less than zeroif (totalCalories < 0="" ||="" fatgrams=""><>cout < "="" total="" calories="" or="" fat="" grams="" can="" not="" be="" less="" than="" zero="">else{if (fatCalories > totalCalories)cout < "\ninvalid="" -="" there="" are="" more="" calories="" in="" fatgrams="">< "grams="" of="" fat="" than="" you="" entered="" for="" total="" calories:="">}// Static cast on the fat percentagefatPercentage = static_cast (fatCalories) / totalCalories;// Calculate fat percentageif (fatPercentage *= 100)cout < "percentage="" of="" fat:="">else{if (fatPercentage <>cout < "\nthat="" food="" is="" low="" in="" fat:="">elsecout < "\nthat="" food="" is="" not="" low="" in="">}return 0;}
// Calculate fat percentageif (fatPercentage *= 100)cout < "percentage="" of="" fat:="">else{if (fatPercentage <>cout < "\nthat="" food="" is="" low="" in="" fat:="">elsecout < "\nthat="" food="" is="" not="" low="" in="">}return 0;}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here