I cannot get my printTotal function to call. It says I am missing identifiers. The read function works fine, but the variables aren't transferring from one function to the other. The assignment says I cannot call one function inside the other. I can only call functions from within the main function. I am not finished programming the printTotal function, but I only need to get the function to call atm. I cannot get them to operate without declaring variables. I must be missing something fundamental to calling functions.
The error message is saying "Identifier "spool", "stock", "shipping" is undefined.
#include <iostream>
#include <iomanip>
using namespace std;
double readSpools() {
int spool, stock;
double shipping = 12.99;
char choice;
cout << "Spools to be ordered\n";
cin >> spool;
while (spool <= 0) {
cout << "Spools order must be 1 or more";
return false;
}
cout << "Spools in stock\n";
cin >> stock;
while (stock <= 0) {
cout << "Spools in stock must be 0 or more";
return false;
}
cout << "Special shipping and handling (y or n)\n";
cin >> choice;
if (choice == 'y' || choice == 'Y') {
cout << "Shipping and handling amount\n";
cin >> shipping;
if (shipping <= 0) {
cout << "The spool shipping and handling charge must be 0.0 or more";
return false;
}
return shipping, spool, stock;
}
}
void printTotal(int spool, int stock, double shipping) {
if (stock >= spool) {
cout << "spools ready to ship: " << spool << endl;
cout << "The subtotal is $" << spool * 100 << ".\n";
cout << "The shipping and handling charges are $" << spool * shipping << ".\n";
cout << "The order total is $" << spool * (100 + shipping) << ".\n";
} else {
cout << "Spools ready to ship: " << stock << endl;
cout << "Spools on backorder: " << 0 - (stock - spool) << endl;
cout << "The subtotal is $" << stock * 100 << ".\n";
cout << "Total shipping and handling charges: $" << stock * shipping << ".\n";
cout << "The order total is $" << stock * (100 + shipping) << ".\n";
}
}
//the read function works, but the printTotal function will not call.
int main() {
readSpools();
printTotal(spool, stock, shipping);
return 0;
}