< previous page page_114 next page >

Page 114
const float PRICE = 150000.0; // Selling price less land
int main() { float grossFootage;// Total square footage
    float livingFootage;        // Living area
float costPerFoot;    // Cost/foot of living area
cout.setf(ios::fixed, ios::floatfield);  // Set up floating pt.
cout.setf(ios::showpoint);      //   output format

grossFootage = LENGTH * WIDTH * STORIES; livingFootage =
 grossFootage - NON_LIVING_SPACE; costPerFoot = PRICE /
livingFootage; cout < Cost per square foot is 
< setw(6) < setprecision(2) < costPerFoot < endl;
return 0; }
Now look at the same program with proper formatting:
//******************************************************************
// HouseCost program
// This program computes the cost per square foot of
// living space for a house, given the dimensions of
// the house, the number of stories, the size of the
// nonliving space, and the total cost less land
//******************************************************************
#include <iostream.h>
#include <iomanip.h>  // For setw() and setprecision()
const float WIDTH = 30.0;               // Width of the house
const float LENGTH = 40.0;              // Length of the house
const float STORIES = 2.5;              // Number of full stories
const float NON_LIVING_SPACE = 825.0;   // Garage, closets, etc.
const float PRICE = 150000.0;           // Selling price less land
int main()
{
    float grossFootage;         // Total square footage
    float livingFootage;        // Living area
    float costPerFoot;          // Cost/foot of living area

    cout.setf(ios::fixed, ios::floatfield);   // Set up floating pt.
    cout.setf(ios::showpoint);                //   output format

    grossFootage = LENGTH * WIDTH * STORIES;
    livingFootage = grossFootage - NON_LIVING_SPACE;
    costPerFoot = PRICE / livingFootage;

    cout < Cost per square foot is 
         < setw(6) < setprecision(2) < costPerFoot < endl;
    return 0;
}

(text box continues on next page)

 
< previous page page_114 next page >