I need help with this program. I do not know how I would calculate to find out the gallons as well as the cost as pictured in my output. How would you do this?
Here is my output:
For each student, you will get the gallon of paint
Input the length: 5
Input the width: 4
Input the cost of a gallon: $5.50
It will take 0 gallon(s) to paint an
area of 5 square feet at a total
cost of $0.00.
Press any key to continue . . .
#include <iostream>
#include <iomanip>
#include <string>
using namespace std ;
// function prototypes
int GetLength();
int GetWidth();
double GetGallonCost();
int ComputeArea( int, int );
int FindGallons( int );
double ComputeCost( double, int );
void PrintResults( int, int, double );
// global constants
const int COVERAGE = 200; // 1 gallon of paint will cover 200 sq. ft.
int main()
{
// local variable declarations for main
int length; // length of the region to be covered
int width; // width of the region to be covered
int area; // area of the region to be covered; long int
// would be required to store large areas
int gallons; // number of gallons needed to cover the region
float gallon_cost; // price of a gallon of paint
float paint_cost; // the cost of the paint needed
char choice = 'Y';
while( choice =='Y' || choice == 'y'){
system("CLS");
cout << "For each student, you will get the gallon of paint" << endl;
// input data
length = GetLength();
width = GetWidth();
gallon_cost = GetGallonCost();
// process data
area = ComputeArea( length, width );
gallons = FindGallons( area ); // find number of gallons to
paint_cost = ComputeCost( gallon_cost, gallons ); // compute cost of paint
// print results
PrintResults( gallons, area, paint_cost );
cout << "\nWould you like to perform another calculation?(Y/N): ";
cin >> choice;
}
cout << "\nDriver Name: Tyler Bazan" << endl;
cout << "Navigator Name: Peter Langlands" << endl;
cout << "Date: Febrauary 24, 2011" << endl;
cout << "Lab CRN 26682\n" << endl;
system ("pause");
return(0);
}
//**********************************************************************
//Function Name: GetLength
// Prompts the user to input the lenth of a rectangular room
// Returns the int value input by the user
//**********************************************************************
int GetLength()
{
int length;
cout << "\nInput the length: ";
cin >> length;
return length;
}
//*********************************************************************
//Function Name: GetWidth
// Prompts the user to input the width of a rectangular room
// Returns the int value input by the user
//**********************************************************************
int GetWidth()
{
int width;
cout << "\nInput the width: ";
cin >> width;
return width;
}
//**********************************************************************
//Function Name: GetGallonCost
//Prmpts the user to input the cost of a gallon of paint
//Returns the value input by the user
//**********************************************************************
double GetGallonCost()
{
int gallon_cost;
cout << "\nInput the cost of a gallon: $";
cin >> gallon_cost;
cout << fixed << showpoint << setprecision(2);
return gallon_cost;
}
//**********************************************************************
//Function Name: ComputeArea
// Formal parameters are the length and width of a rectangle
// Calculates and returns the rectangle area
//**********************************************************************
int ComputeArea( int length, int width )
{
int area;
area = length * width;
return length;
}
//**********************************************************************
//Function Name: FindGallons
//Calculates and returns the number of gallons of paint needed
// Formal parameter is the area to be painted
// Global constant COVERAGE tells the number of square feet
// covered by one gallon
// Calculates and returns the number of gallons
// Paint must be purchased by the gallon so if (Area / COVERAGE)
// yields a remainder, round up to the highest integer
//**********************************************************************
int FindGallons( int paint_area )
{
int Area;
paint_area = (Area/COVERAGE);
return paint_area;
}
//**********************************************************************
//Function Name: ComputeCost
//Computes how much it would cost to buy all the paint necessary
//to cover the region.
// Formal parameters are the cost per gallon and the number of gallons
// of paint needed
//**********************************************************************
double ComputeCost( double gallon_price, int num_gallons )
{
double paint_cost;
paint_cost = gallon_price * num_gallons;
return paint_cost;
}
//**********************************************************************
//Function Name: PrintResults
// A void function
// Formal parameters are the number of gallons, the area to be painted,
// and the total cost of the paint required.
// Prints a message to the screen stating the number of gallons,
// the area, and the post of the piant.
//**********************************************************************
void PrintResults( int gallons, int area, double paint_cost )
{
string results;
cout << "\nIt will take " << gallons << " gallon(s) to paint an"
<< " \narea of " << area << " square feet at a total"
<< " \ncost of $" << paint_cost << "." << endl;
}
// end of function declarations