/*************************************************/ // paint3.cpp // R. A. Hillyard // Last Modified: 09/10/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 // This version allows the user to enter a sentinel when finished /*************************************************/ #include <iostream> using namespace std; const float SqFtPerGal = 350.0; int main( void ) { bool flag; int count; float feet; float inches; float length; float height; float numGallons; float totalArea; //initialization phase totalArea = 0.0; //total so far count = 0; //how many times through the loop flag = true; while(flag) { cout << endl << "Area #" << count+1 << " Enter the length in feet and inches: (-1, -1 to quit)"; cin >> feet >> inches; if(feet == -1) { flag = false; } else { length = feet + inches/12.0; cout << "Area #" << count+1 << " Enter the height in feet and inches: "; cin >> feet >> inches; height = feet + inches/12.0; totalArea += length * height; count++; }//end else }//end while numGallons = totalArea/SqFtPerGal; cout << "\nFor " << count << " areas, "; cout << "\nYou will need: " << numGallons << " gallons of paint to cover"; cout << "\nthe area of " << totalArea << " square feet" << endl; return 0; } /***************Program Output***********************/ Area #1 Enter the length in feet and inches: (-1, -1 to quit) 100 6 Area #1 Enter the height in feet and inches: 55 9 Area #2 Enter the length in feet and inches: (-1, -1 to quit)200 0 Area #2 Enter the height in feet and inches: 79 3.4 Area #3 Enter the length in feet and inches: (-1, -1 to quit)-1 -1 For 2 areas, You will need: 61.313 gallons of paint to cover the area of 21459.5 square feet