i am supposed to write a program to display the status of an order for a company.
"The program should have a function that asks for the following data:
- The number of spools ordered.
- The number of spools in stock.
- If there are special shipping and handling charges.
The gathered data should be passed as arguments to another function that displays blablabla"
my question is how does the first function return all three pieces of information to main so it can be passed to the second function?
i just made three separate functions for it and it works but it seemed like the book implied one function should do all that work.
fyi structs and classes have not been covered yet so please dont reply with an answer in that form of solution.
here is my code: (not perfected yet with calculations but just want answer to my question)
Code:#include <iostream> #include <iomanip> using namespace std; void getOrdered(double &); void getStock(double &); double specialShipping(); void displayData(double, double, double); int main() { double ordered, stock; double shipping; getOrdered(ordered); getStock(stock); shipping = specialShipping(); displayData(ordered, stock, shipping); return 0; } void getOrdered(double &ord) { cout << "Enter the number of spools ordered: "; cin >> ord; } void getStock(double &st) { cout << "Enter the number of spools in stock: "; cin >> st; } double specialShipping() { char choice; double shipping = 0; do { cout << "Are there any special shipping options? (Y or N): "; cin >> choice; }while(choice != 'y' && choice != 'Y' && choice != 'n' && choice != 'N'); if (choice == 'y' || choice == 'Y') { cout << "Enter the shipping in dollars per spool: "; cin >> shipping; } else if (choice == 'n' || choice == 'N') { shipping = 10; } return shipping; } void displayData(double ord, double st, double ship) { if (ord > st) { cout << "Number of spools on backorder: " << ord - st << endl; } else cout << "Number of spools ready to ship: " << ord << endl; cout << "Subtotal of portion ready to ship: $" << fixed << setprecision(2) << (ord * 100) << endl; cout << "Total shipping and handling: $" << fixed << setprecision(2) << ship << endl; cout << "Total: $" << fixed << setprecision(2) << (ord*100) + ship << endl; }