Programming Challenge Chapter 3 – Q #1 Miles per Gallon – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #1  Miles per Gallon – Tony Gaddis – Starting Out With C++


Problem: -

Write a program that calculates a car s gas mileage. The program should ask the user to enter the number of gallons of gas the car can hold, and the number of miles it can be driven on a full tank. It should then display the number of miles that may be driven per gallon of gas.

Solution: -

#include <iostream>

using namespace std;

int main()

{

      int gass_gallon, number_of_miles;

      int result = 0;

      cout << "Enter Gallon Of Gas: ";

      cin >> gass_gallon;

      cout << "Enter Miles: ";

      cin >> number_of_miles;

      result = gass_gallon * number_of_miles;

      cout << "Number Of Miles Can Travel: " << result;

      return 0;

}


This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.



Explanation of this Solution


  1. Declare two int variables for calculation.
  2. Declare another variable int variable.
  3. Take input  Gallon Of Gas from the user by using cin.
  4. Take input  Miles from the user by using cin.
  5. Calculate the result by multiplying gas gallon and miles,
  6.  In last, display output on the screen.
  7. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File




Thanks!  


Post a Comment

0 Comments