Posted by Viper on Monday, April 4, 2011 at 8:48pm.
I'll give you a headstart:
Input:
input fat_grams;
input calories;
Validate:
- Make sure the number of fat grams and calories are not less than 0.
- the number of calories cannot exceed fat grams X 9.
Calculations:
- Percentage of calories from fat = (fat grams x 9) / calories
- is it low-fat?
Output:
- Print input data
- print output information
my while loop will not work for this, it is, while fatGrams < 0 or calories < 0 or calories > fatGrams * 9
typically one would code like this:
do{
print: instructions;
enter fatGrams;
enter calories;
}while(data unsatisfactory);
So that it would request data at least once.
Do
Display Error: "Error: The number of calories and fat grams cannot be less than 0. The number of calories cannot be greater than fat grams * 9."
Display "Enter the correct number of calories."
Input calories
Display "Enter the correct number of fat grams."
Input fatGrams
While fatGrams > 0 and calories > 0 and calories < fatGrams * 9
the while part was just a while loop i originally did and it worked
it would also work with a do-while loop like what i typed above?
Basically, yes, it works.
From the user's point of view, it does not seem logical to see "Error,..." before he types in anything.
I would replace the "error" message with an insisting message, such as:
"Please enter non-negative values for ...., and ensure that ...< 9*..."
It would be nicer, of course, to insert a message indicating an error for the second time around, such as:
If (count greater than 1) Display "Sorry, there is an error in the input. Please follow the instructions carefully."
For this, you'll need a counter called count that was set to 1 before entering the loop, and incremented by 1 at the end of the loop.
Related Questions
Programming - Submit pseudocode and a flowchart for the following programming ...
Computer Programing & Logic Design - Submit pseudocode and a flowchart for ...
Math - Coould someone please let me know if I did this equation correctly. This ...
Computer Programing & Logic Design - Submit pseudocode and a flowchart for ...
Computer Programing & Logic Design - Submit pseudocode and a flowchart for ...
Computer Programing & Logic Design - Submit pseudocode and a flowchart for ...
math - how can i make the content equal the same %? what did i do wrong? Lunch: ...
math - how can i make the content equal the same %? what did i do wrong? Dinner...
math - how can i make the Protein content equal the same %. what did i do wrong...
Algebra - Pepperidge Farm Goldfish is a snackfood for which 40% of its calories ...
For Further Reading