*Pass by value, reference
I need to write 4 functions including main to display a report with the size of room in square feet, cost of carpet,cost to install the carpet. I am having trouble with using the last function to compute the costs using data from the other functions and then going back to main to report 3 values.
#include <iostream>
#include <iomanip>
using namespace std;
void getInput(double &, double &, double &);
double computeArea(double , double ) ;
void computeCosts(double&,double &);
const int INCHESPERSQUAREFOOT=144; //constant to calculate area
int main(){ //main function to call all nessesary functions and display results
double width,
length,
carpetPerfootcost,
area,
instalcost,
totalCarpetcost;
cout<<"Ace Carpet Company Cost estimate";
cout<<endl;
//call getInput and get the users width, length and cost of the carpet
getInput(width, length, carpetPerfootcost);
//call compute area to preform the nessecary calculations and return the area
//call compute costs to
computeCosts(totalCarpetcost,instalcost);
cout<<setprecision(2)<<fixed;
cout<<"The area in square feet is: "<<computeArea(width, length);
cout<<"The cost of the carpet is: "<<totalCarpetcost<<endl;
cout<<"The cost to install the carpet is "<<instalcost<<endl;
return 0;
}
void getInput(double &width, double &length, double &carpetPerfootcost)
{
cout<<"please enter the width: "<<endl;
cin>>width;
while(width<=0)
{cout<<"Error, please enter a width with a postive value: ";
cin>>width;}
cout<<"please enter the length: "<<endl;
cin>>length;
while(length<=0)
{cout<<"Error, please enter a length with a postive value: ";
cin>>length;}
cout<<"please enter the price of the carpet: "<<endl;
cin>>carpetPerfootcost;
while(carpetPerfootcost<=0)
{cout<<"Error, please enter a price with a postive value: ";
cin>>carpetPerfootcost;}
}
double computeArea(double width, double length)
{
return (width*length)/(INCHESPERSQUAREFOOT);
}
void computeCosts(double &totalCarpetcost, double &instalcost)
{
const double COSTPERFOOTINSTAL=5.75;
totalCarpetcost=carpetPerfootcost*area; instalcost=area*COSTPERFOOTINSTAL;}