/*************************************************/ // paint1b.cpp // R. A. Hillyard // Last Modified: 02/05/2001 // // Determine the number of gallons of paint needed for a given area. // The user will enter the length and height in feet and inches // // Modifyed to show how to format floating point numbers for cout /*************************************************/ #include <iostream>
using namespace std;
const float sqFtPerGal = 350.0; int main() { float feet, inches, length, height, area, numGallons; cout << "Enter the length in feet and inches: "; cin >> feet >> inches; length = feet + inches/12.0; cout << "\nEnter the height in feet and inches: "; cin >> feet >> inches; height = feet + inches/12.0; area = length * height; numGallons = area/sqFtPerGal; //set floating point output to 2 decimal places cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2);
cout << "\nYou will need: " << numGallons << " gallons of paint to"; cout << "\ncover the area of " << area << " square feet\n\n"; return 0; }
/****************program output****************/
Enter the length in feet and inches: 55.6 8 Enter the height in feet and inches: 44 9.5 You will need: 7.20 gallons of paint to cover the area of 2520.28 square feet