Browsing daniweb for a couple weeks and you guys really help but in this lab me and my partners were a bit stumped, the purpose was to pass one set through pointers and the rest arrays. In my opinion a bit silly but whatnot, here's the latest code (we have everything its just not working) my partner sent me, email messes it up. Thanks

#include <iostream>
#include <iomanip>

using namespace std;

const double LABOR_COST = 0.35;
const double TAX_RATE = 0.085;

double getData(double *length, double *width, double *discount, double 
*carpetCost);
double calculate();
void printResults();
double calculateInstall(double &area, double &carpetCost);
double calculateSubtotal();
double calculateTotal;

int main()
{
 double area;
 double length, width, discount, carpetCost;
 double labor, installPrice;

 getData(&length, &width, &discount, &carpetCost);

 area = length * width;

// calculate(calculateInstall, calculateSubtotal, calculateTotal);

 calculateInstall(labor, installPrice);

 cout << "Labor cost is: " << labor << endl;
 cout << "Install Price is: " << installPrice << endl;
 cout << endl;

 return 0;
}

double getData(double *length, double *width, double *discount, double 
*carpetCost)
{
 cout << "Length of room (feet):\t\t";
 cin >> *length;

 cout << "Width of room (feet):\t\t";
 cin >> *width;

 cout << "Customer discount (percent):\t";
 cin >> *discount;

 cout << "Cost per square foot:\t\t";
 cin >> *carpetCost;
 cout << endl;

 return *length, *width, *discount, *carpetCost;
}

double calculateInstall(double &area, double &carpetCost)
{
 double labor, installPrice;

 labor = area * LABOR_COST;
 installPrice = area * carpetCost;

 return labor, installPrice;
}

>>the purpose was to pass one set through pointers and the rest arrays

yes it is silly -- arrays are always passed as pointers. The below are both identical and interchangable. The problem with both of these is that they are both arrays of unspecified size. And the first one may not be an array at all but a pointer to just one int. So the function foo() has to be written smart enough to know what is going on, and the calling fuction has to pass an object of the type that foo() knows about.

foo(int *array);
foo(int array[])

Alright, actually i was talking to someone about arrays while typing that. Ignore some of what I said.
What we need to do was the getData func was to use pointers, while the other functions used pass by reference or pass by value. I've looked through my book but am still confused on why its not working. And this is the latest code.

#include <iostream>
#include <iomanip>


using namespace std;

const double LABOR_COST = .35;
const double TAXRATE = .085;

void getData( double * , double *, double *, double *);
void calculate( double & , double & , double &, double &, double &, 
double &, double &, double &, double &, double &, double &, double &, 
double & );
void printResults( double &, double &, double &, double &, double &, 
double &, double &, double &, double &, double &, double &, double & );
void calculateInstall( double &, double &, double , double, double, 
double & , double );
void calculateSubtotal( double , double &, double &, double );
void calculateTotal( double &, double&, double );


int main()
{

 
 double length, width, discount, carpetCost, area, labor, installPrice, 
discountedPrice, Total, totalCarpet, totalDiscount, subTotal, Tax;

 getData ( &length, &width, &discount, &carpetCost);

 area = length * width; // calculates the area given

 calculate ( area, carpetCost, installPrice, labor, discountedPrice, 
discount, Total, totalCarpet, totalDiscount, length, width, subTotal, 
Tax );

 printResults( carpetCost, installPrice, totalCarpet, labor, discount, 
discountedPrice, length, width, area, subTotal, Tax, Total);


    return 0;
}


void getData ( double *length , double *width , double *discount , 
double *carpetCost )
{
 cout << "Length of the room (feet):\t" << " " ;
 cin >> *length;

 cout << "Width of the room (feet):\t " ;
 cin >> *width;

 cout << "Customer discount (percent):\t " ;
 cin >> *discount;

 cout << "Cost per square foot:\t\t ";
 cin >> *carpetCost;

}

void calculate (double &area, double &carpetCost, double &installPrice, 
double &labor, double &discountedPrice, double &discount, double 
&Total, double &totalCarpet, double &totalDiscount,
    double &length, double &width, double &subTotal, double &Tax )
{
 calculateInstall ( area, carpetCost, installPrice, labor, totalCarpet, 
totalDiscount, discount );

 calculateSubtotal ( subTotal, installPrice, totalDiscount, Tax );

 calculateTotal (subTotal, Tax, Total);
    
 //printResults( carpetCost, totalCarpet, labor, discount, 
totalDiscount, length, width, area, installPrice);

}


void calculateInstall ( double & area, double &carpetCost, double 
installPrice, double labor, double totalCarpet, double &discount, 
double totalDiscount)
{
 totalCarpet = area * carpetCost; // total cost of the carpet
 labor = area * LABOR_COST; // calculates the total cost of the labor
 installPrice = totalCarpet + labor; // installed price
 totalDiscount = installPrice * discount; //total amount of the discount
 
    
}

void calculateSubtotal ( double subTotal, double &installPrice, double 
&totalDiscount, double Tax )
{
 subTotal = installPrice - totalDiscount;
 Tax = subTotal * TAXRATE;


}

void calculateTotal ( double &subTotal, double &Tax, double Total)
{
 Total = subTotal + Tax ;

}
void printResults( double &carpetCost, double &installPrice, double 
&totalCarpet, double &labor, double &discount, double &discountedPrice, 
double &length, double &width, double &area, double &subTotal,
      double &Tax, double &Total )
{
 cout << setw (25) << "MEASUREMENT" << endl;
 cout << endl;
 cout << "Length" << setw (29) << length << "ft" << endl;
 cout << "Width" << setw (30) << width << "ft" << endl;
 cout << "Area" << setw (31) << area << " square ft" << endl;
 cout << setw (23) << " CHARGES " << endl;
 cout << endl;
 cout << "DESCRIPTION \t COST/SQ.FT. \t CHARGE/ROOM " << endl;
 cout << "----------- \t ----------- \t ----------- " << endl;
 cout << "Carpet " << fixed << setprecision (2) << setw (18) << 
carpetCost <<setw (10) << "$" << totalCarpet << endl;
 cout << "Labor " << setw (19) << LABOR_COST << setw (19) << labor << 
endl;
 cout << endl;
 cout << "\t\t\t\t  ----------" << endl;
 cout << "INSTALLED PRICE" << right << setw (30) << installPrice << 
endl;
 cout << "Discount" << setw (19) << fixed << setprecision (0) << 
discount << "%" << setw (12) << discountedPrice << endl;
 cout << "SUBTOTAL" << setw (20) << setprecision (2) << subTotal << 
endl;
 cout << "Tax" << setw (10) << setprecision (2) << Tax << endl;
 cout << "Total" << setw (10) << setprecision (2) << Total << endl;



}

I think the problem is the use of uninitialized variables. Set them to 0 and the output will look reasonable. I don't know if it is correct, but the program displays reasonable numbers.

int main()
{

 double length = 0, width = 0, discount = 0, carpetCost = 0, area = 0,
	 labor = 0, installPrice = 0, 
	discountedPrice = 0, Total = 0, totalCarpet = 0, totalDiscount = 0,
	subTotal = 0, Tax = 0;
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.