fork download
  1. // Erfan Haji Ramezan – CS1A – Chapter 2 Homework
  2. /******************************************************************************
  3.  *
  4.  * MPG CALCULATOR
  5.  * ____________________________________________________________________________
  6.  * This program asks the user how far a car can go on a full tank of gas,
  7.  * and how many gallons the tank holds. Then it calculates the miles per gallon.
  8.  *
  9.  * Formula:
  10.  * MPG = Distance / Tank Size
  11.  * ____________________________________________________________________________
  12.  * INPUT:
  13.  * distance : miles the car can drive before refueling
  14.  * tankSize : gas tank size in gallons
  15.  *
  16.  * OUTPUT:
  17.  * mpg : miles per gallon
  18.  *
  19.  ******************************************************************************/
  20.  
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main() {
  25. float distance, tankSize, mpg;
  26.  
  27. cout << "Enter how many miles the car can travel on a full tank: ";
  28. cin >> distance;
  29.  
  30. cout << "Enter the gas tank size in gallons: ";
  31. cin >> tankSize;
  32.  
  33. mpg = distance / tankSize;
  34.  
  35. cout << "\nThis car gets " << mpg << " miles per gallon." << endl;
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Enter how many miles the car can travel on a full tank: Enter the gas tank size in gallons: 
This car gets inf miles per gallon.