Write the psudo code for this problem You want to decide whether you should driv
ID: 3743214 • Letter: W
Question
Write the psudo code for this problem
You want to decide whether you should drive your car to work or take the train. You know the one-way distance from your home to your place of work, and the fuel efficiency of your car (in miles per gallon). You also know the one-way price of a train ticket. You assume the cost of gas at $4 per gallon, and car maintenance at 5 cents per mile. Write an algorithm to decide which commute is cheaper.
(Please write the psudo code only and list the steps, thank you)
Explanation / Answer
// Assigning values of distance, fuel efficiency, to variables d and f
STEP 1- d=one_way_distance
STEP 2- f=fuel_efficiency
STEP 3- car_cost=(d/f)*4+0.05*d /*total cost in dollars. d/f=number of gallons required. This multiplied by 4 would give the total cost for fuel. The car takes 5 cents or 0.05 dollars per mile. So 0.05*d would give the total maintenance cost. Adding these two would give the total cost for commuting by car in dollars */
STEP 4- if car_cost > train_ticket // train_ticket should be in dollars
Print("Commuting by train is cheaper")
else
Print("Commuting by car is cheaper")
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.