Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear
- % Filename: Rivera13p3
- % Jeremy Rivera
- % EGR 120-001
- % User inputs the tank size, amount of gas in the tank, and miles per galon used.
- % The program calculates percentage in the tank, gas needed, and distance traversed
- % VARIABLE DECLARATION
- % tanksize (real) User inputs size of tank in gallons
- % gas_in_tank (real) User inputs the amount of gas already in the tank
- % gaspercent (real) User inputs the percentage of gas in terms of gas gauge
- % gasneeded (real) User inputs the amount of gas needed for the tank to be full
- % distance (real) User inputs distance desired to traverse
- % mpg (real) User inputs the amount of miles per gallon the car uses
- tanksize=input('The size of the tank is: ');
- gas_in_tank=input('The amount of gas in gallons currently in the tank: ');
- mpg=input('Amount of miles per galon the car uses: ');
- gaspercent=gas_in_tank/100;
- fprintf('The gas tank is %d percent full\n',gaspercent);
- gasneeded=gaspercent*tanksize;
- fprintf('The gas needed to fill out the tank in gallons is: %0.2f\n',gasneeded);
- distance=gasneeded*mpg;
- if distance<200
- fprintf('The tank needs more gas to traverse the distance in miles\n');
- else
- fprintf('The tank is properly filled up for travel\n');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement