Advertisement
JerBear33

Untitled

Nov 24th, 2021
1,646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.25 KB | None | 0 0
  1. clc
  2. clear
  3.  
  4.  
  5. % Filename: Rivera13p3
  6. % Jeremy Rivera
  7. % EGR 120-001
  8. % User inputs the tank size, amount of gas in the tank, and miles per galon used.
  9. % The program calculates percentage in the tank, gas needed, and distance traversed
  10.  
  11. % VARIABLE DECLARATION
  12. %     tanksize (real) User inputs size of tank in gallons
  13. %     gas_in_tank (real) User inputs the amount of gas already in the tank
  14. %     gaspercent (real) User inputs the percentage of gas in terms of gas gauge
  15. %     gasneeded (real) User inputs the amount of gas needed for the tank to be full
  16. %     distance (real) User inputs distance desired to traverse
  17. %     mpg (real) User inputs the amount of miles per gallon the car uses
  18.  
  19. tanksize=input('The size of the tank is: ');
  20. gas_in_tank=input('The amount of gas in gallons currently in the tank: ');
  21. mpg=input('Amount of miles per galon the car uses: ');
  22.  
  23. gaspercent=gas_in_tank/100;
  24. fprintf('The gas tank is %d percent full\n',gaspercent);
  25. gasneeded=gaspercent*tanksize;
  26. fprintf('The gas needed to fill out the tank in gallons is: %0.2f\n',gasneeded);
  27. distance=gasneeded*mpg;
  28. if distance<200
  29.   fprintf('The tank needs more gas to traverse the distance in miles\n');
  30. else
  31.   fprintf('The tank is properly filled up for travel\n');
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement