Answer to Question #261258 in C++ for nuuuurrrii

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.


1
Expert's answer
2021-11-04T16:26:00-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS