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

Recommended Answers

All 11 Replies

#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;

}
   
    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

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;

}
   
    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

line 140: The value of Area is undefined because it has not been initialized to anything. I expect what you meant to say is Area = paint_area / COVERAGE.

According to my output, is there a reason why it skips the end statement asking if I want to perform another calculation and instead it ends the program. How do I fix this?

#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;

}    
   
    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 area;
}


//**********************************************************************
//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

Output:

For each student, you will get the gallon of paint

Input the length: 10

Input the width: 20

Input the cost of a gallon: $25.00

It will take 1 gallon(s) to paint an
area of 200 square feet at a total
cost of $25.00.

Would you like to perform another calculation?(Y/N):

Press any key to continue . . .

According to my output, is there a reason why it skips the end statement asking if I want to perform another calculation and instead it ends the program. How do I fix this?

Output:

For each student, you will get the gallon of paint

Input the length: 10

Input the width: 20

Input the cost of a gallon: $25.00

It will take 1 gallon(s) to paint an
area of 200 square feet at a total
cost of $25.00.

Would you like to perform another calculation?(Y/N):

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 area;
}


//**********************************************************************
//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

You need to flush the input keyboard buffer before asking for choice. When you enter a number you also have to press <Enter> key -- that key is not removed from the keyboard buffer. so the next request for a char will get the '\n' that's already in the keyboard buffer.

int ComputeArea( int length, int width )
{
int area;
area = length * width;
return length;
}

That should definitely not return length.. it should actually return area.. and is messing up your calculations..

Also to round up the amount of gallons:

int FindGallons( int paint_area )
{
int Area;
paint_area = (Area/COVERAGE);
return paint_area;
}

you would do something like:

int FindGallons( int paint_area )
{
int Area;
double AreaRounding = (Area%COVERAGE);  //Returns the remainder of the division if any..
paint_area = ((Area/COVERAGE) + AreaRounding);
return paint_area;
}
//use this to do the rounding..
double round( double value )
  {
    return floor( value + 0 );
  }

Since 144 is less than 200, it comes out to 0.7 gallons, but in my output it shows 0 which will make the cost 0. How do I make it so, it shows a decimal value for gallons.

*Output

Input the length: 12

Input the width: 12

Input the cost of a gallon: $25.00

It will take 0 gallon(s) to paint an
area of 144 square feet at a total
cost of $0.00!

Would you like to perform another calculation?(Y/N):

#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
    double gallon_cost; // price of a gallon of paint
    double paint_cost;  // the cost of the paint needed
    char choice = 'Y';
    
    while( choice =='Y' || choice == 'y'){
    system("CLS");
    
    
    // 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;
}
   
   

    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 << "Input 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()
  {
   double gallon_cost;

   cout << "\nInput the cost of a gallon: $";
   cin >> gallon_cost;
   cout << fixed << showpoint << setprecision(2) << endl;
   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 area;
}


//**********************************************************************
//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 << "It 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
commented: We know it's C++ and we know you need help. Come up with more informative thread titles. -5

your code is

int FindGallons( int );  //line 12...   it should be double FindGallons(double);

and

//lines 134-138
int FindGallons( int paint_area )
{
  int area;
  paint_area = (area/COVERAGE);
  return paint_area;
}

Lines 134-138 should be..

double FindGallons( double paint_area )
{
  double area;
  paint_area = (area/COVERAGE);
  return paint_area;
}

double = decimal places.. or else use float..

Thought I already showed you that in the previous thread you posted.. I declared rounding as double.. AreaRounding..

For future reference try to post the problem in the same thread rather than start a brand new one unless really necessary... And someone passing through should see it.

I've compiled your program this time to see what you are talking about... your while loop in the main() determines how your program will run... so while the user keeps entering Y or y, the program will keep running.. but when the user presses N or n, the program will then give the option to continue.. and when you do continue, it exits..

So far Each time I pressed Y or y, the program asks me to enter a new length.. and a new width. This is how the program is supposed to run. Nothing is wrong with is :S... Your "n" character on your keyboard maybe stuck..

Try the code below.. It works for the decimals that you wanted in your previous post.. I've shown you this in the previous threads but it doesnt seem like I explained well enough so instead i've just changed a few of your int's to double's..

Other than that, your program is perfect, the input stream is fine.. it does not constantly repeat if the user doesnt press y.. So I will assume your keyboard 'n' character button may be down or stuck.

example: area/COVERAGE can now out put 0.XX gallons instead of outputting 0.00 if area < coverage... (I changed approx. 3 int's to double's)

#include <iostream>
#include <iomanip>
#include <string>
using namespace std ;


// function prototypes
int GetLength();
int GetWidth();
double GetGallonCost();
double ComputeArea( int, int );
double FindGallons( double );
double ComputeCost( double, double );
void PrintResults( double, double, 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
    double   gallons;     // number of gallons needed to cover the region
    double gallon_cost; // price of a gallon of paint
    double 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 << "Input 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()
  {
   double gallon_cost;

   cout << "\nInput the cost of a gallon: $";
   cin >> gallon_cost;
   cout << fixed << showpoint << setprecision(2) << endl;
   return gallon_cost;
  }


//**********************************************************************
//Function Name: ComputeArea
// Formal parameters are the length and width of a rectangle
// Calculates and returns the rectangle area

//**********************************************************************
double ComputeArea( int length, int width )
{
    double area;
    area = length * width;    
    return area;
}


//**********************************************************************
//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

//**********************************************************************
double FindGallons( double paint_area )
{
  double 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, double 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( double gallons, double area, double paint_cost )
  {
    string results;
    cout << "It 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

Okay, this was scattered across 4 different threads. I have merged them into one. If you wonder why it seems a bit of a mess, that would be why.

Plang007, keep it in one thread in the future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.