# Gas Price Algorithm

### Gas Price Algorithm

To compare the price of gas in the United States and Italy, we need to convert Euros to dollars and also convert liters to gallons.

- We need to know the exchange rate of dollars to gallons. In February of 2015 we can do a search and find that $1=0.88 Euros.
- But we have the price in Euros and want that in dollars. What is the formula?
- 1/0.88 gives us 1 Euro =$1.13
- So now we can multiple the cost of 1.64 € per liter by 1.13 and find that the Italians are paying $1.85 per liter.
- If the Italians are paying the equivalent of $1.85 per liter, what would they pay for a gallon?
- Now we need to know how to convert liters to gallons.
- One liter = 0.264172 gallons
- We need to reverse that by dividing 1/0.264172 to get 3.785412534 liters = 1 gallon.
- Finally, we can multiply the cost per liter ($1.85) by 3.79 to get the price per gallon: The Italians are paying about $7 per gallon.
*The big difference in price is mainly due to taxes.*

When we write the program what values are constant? Which ones are variable?

Remember, you only want to ask the user for those values that are variables, and only ask the user to input raw data, not calculated values.

Pseudo-code

Try writing the program. You should get the same answer if you put in the same data.

Like us on Facebook:

**OER: Open Educational Resource**

Author: Janet E. Joy; Publisher: Zebra0.com

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Creative Commons Attribution-NonCommercial 4.0 International License

Last modified: April 15 2016 15:53:06.