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.
#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;
}
Comments
Leave a comment