Error when I try to call the display function. The comment about it is toward the end of the program.

/*
Lab Lesson 7 Part 1/2
Write a program for the hypothetical Acme Wholesale Copper
Wire Company. This company sells spools of copper wiring for $104
each—write a program that displays the status of an order.
You will need at least three functions (two other than main).
You must use function prototypes for all functions but main.
*/

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

bool read(); // function prototype for the read function
int display(); // function prototype for the display function


// read function below
bool read(int &spoolsOrdered, int &spoolsInStock, double &shippingAndHandling) {

cout << "Spools to be ordered" << endl;
cin >> spoolsOrdered;
if (spoolsOrdered < 1) {
cout << "Spools must be 1 or more" << endl;
return false; // is this allowed or jut return 0?
}

cout << "Spools in stock" << endl;
cin >> spoolsInStock;
if (spoolsInStock < 0) {
cout << "Spools in stock must be 0 or more" << endl;
return false;
}

string shippingOffered;
cout << "Special shipping and handling (y or n)" << endl;
cin >> shippingOffered;
if (shippingOffered == "y") {
cout << "Shipping and handling amount" << endl;
cin >> shippingAndHandling;
if (shippingAndHandling < 0) {
cout << "The spool shipping and handling charge must be 0.0 or more" << endl;
return false;
}
}

return true;
}

int display (int &spoolsOrdered, int &spoolsInStock, double &shippingAndHandling, int &shipSpool, int &spoolBackOrder, double &subtotal, double &shippingCost, double &totalShippingCharges) {

read(spoolsOrdered, spoolsInStock, shippingAndHandling);
cout << "Spools ready to ship: ";
if (shipSpool >= spoolsOrdered) {
cout << shipSpool << endl;
}
spoolBackOrder = spoolsOrdered - spoolsInStock;
shippingCost = 10 * spoolsOrdered;
cout << "Spools on back-order: " << spoolBackOrder << endl;
cout << "Subtotal ready to ship: $" << setw(10) << fixed << setprecision(2) << subtotal << endl;
cout << "Shipping and handling: $" << setw(10) << fixed << setprecision(2) << shippingCost << endl;
cout << "Total shipping charges: $" << setw(10) << fixed << setprecision(2) << totalShippingCharges << endl;

return 0;
}

int main() {
int spoolsOrdered, spoolsInStock, shipSpool, spoolBackOrder;
double shippingAndHandling, subtotal, shippingCost, totalShippingCharges;

read(spoolsOrdered, spoolsInStock, shippingAndHandling);
if (spoolsOrdered > 1) {
display(shipSpool, spoolBackOrder, subtotal, shippingCost, totalShippingCharges);
} // for this display it says no matching function for call to display...why?

return 0;
}


A couple of things:

1. PLEASE learn to use code tags, they make it easier to read and comment on code.

http://www.cplusplus.com/articles/jEywvCM9/

Hint: you can edit your post and add code tags.

2. Your function declarations (prototypes) do not match the parameter list of your function definitions. They need to have the same number of parameters.

You really don't need the prototypes since you define your functions before they are used in main().

3. Your display() function is defined to use 8 parameters, none with defaults. In main() you call the function with 5(!) variables. You are not passing 3 variables the function requires.

Next time include the text of the error(s) you received, our crystal balls are not working.
Thanks so much for the feedback. & about #3 in your reply, I did pass in the 3 other variables the function requires and the problem with it was I'd get the same output that I got from calling the read() function, which was right above display() in the main function...
Your display function is contracted to have 8 parameters passed, not 5. Passing the "missing" variables into a different function doesn't matter.

8 variables are required when you call the function.

display(shipSpool, spoolsInStock, shippingAndHandling, shipSpool, spoolBackOrder, subtotal, shippingCost, totalShippingCharges);

Either pass 8 parameters, or re-define the function to need 5 parameters.
Topic archived. No new replies allowed.