Question #261258

1.     Write a program that prompts the capacity, in gallons, of an automobile fuel tank and the miles per gallon the automobile can be driven. The program outputs the number of miles the automobile can be driven without refueling.


Expert's answer

#include <iostream>

int main()
{
    float capacity;
    float milesPerGallon;

    std::cout << "Enter capacity, in gallons, of an automobile fuel tank: ";
    std::cin >> capacity;
    std::cout << "Enter the miles per gallon the automobile can be driven: ";
    std::cin >> milesPerGallon;

    if(!std::cin)
    {
        std::cout << "Error: invalid data\n";
        return 1;
    }

    std::cout << "Number of miles the automobile can be driven without refueling is " << (capacity / milesPerGallon) << "\n";

    return 0;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS