Write a pseudocode algorithm that calculates and prints the overall MPG (miles p
ID: 3882873 • Letter: W
Question
Write a pseudocode algorithm that calculates and prints the overall MPG (miles per gallon) for a series of miles and gallons user inputs. Use a loop to repeatedly ask the user to enter a miles value and a gallons value. Within the loop, accumulate miles and gallons separately. Use a counter loop to ensure that the loop repeats three times. The algorithm should generate a display of prompts, inputs, and final output that looks like this (italicized values are user inputs): Sample session: Enter miles: 10 Enter gallons: 1 Enter miles: 20 Enter gallons: 2 Enter miles: 10 Enter gallons: 2 Overall MPG = 8 Provide a graceful response if the total gallons equals zero.Explanation / Answer
The pseudocode for the above program in java is as follows:
Pseudocode:
1. Enter number of times you want to calculate for .
Save it in number
2. Enter miles in the integer mile.
Enter gallons in the integer gall.
3. Ask the user value until the limit is reached for the number.
for(i=0;i<number;i++)
4. Now, calculate miles per gallon with the help of given formula
int milespergallon = mile/gall;
5. int overall = milespergallon/number;
Output overall;
Rate an upvote.......Thankyou
Hope this helps......
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.