Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip> // std::setprecision
- using namespace std;
- // Function Declarations
- void readInputData(int& spoolsOrdered, int& spoolsInStock, double& shippingCharges);
- void display(int spoolsOrdered, int spoolsInStock, double shippingCharges);
- int main()
- {
- // Declaring variables
- int spoolsOrdered, spoolsInStock;
- double shippingCharges;
- // Calling the functions
- readInputData(spoolsOrdered, spoolsInStock, shippingCharges);
- display(spoolsOrdered, spoolsInStock, shippingCharges);
- return 0;
- }
- // This function will read the inputs entered by the user
- void readInputData(int& spoolsOrdered, int& spoolsInStock, double& shippingCharges)
- {
- /* This while loop continues to execute
- * until the user enters a valid number
- */
- while (true)
- {
- cout << "Spools to be ordered :";
- cin >> spoolsOrdered;
- if (spoolsOrdered < 1)
- {
- cout << "** Spools Order must be 1 or more **" << endl;
- continue;
- }
- else
- break;
- }
- /* This while loop continues to execute
- * until the user enters a valid number
- */
- while (true)
- {
- cout << "Spools in Stock :";
- cin >> spoolsInStock;
- if (spoolsInStock < 1)
- {
- cout << "** Spools in stock must be 0 or more **" << endl;
- continue;
- }
- else
- break;
- }
- char ch;
- cout << "Special shipping and handling (y or n):";
- cin >> ch;
- if (ch == 'y')
- {
- /* This while loop continues to execute
- * until the user enters a valid number
- */
- while (true)
- {
- cout << "Enter Special Shipping charges :";
- cin >> shippingCharges;
- if (shippingCharges < 0)
- {
- cout << "** The spool shipping and handling charge must be 0.0 or more **" << endl;
- continue;
- }
- else
- break;
- }
- }
- else
- {
- shippingCharges = 11.88;
- }
- }
- // This function will display the output
- void display(int spoolsOrdered, int spoolsInStock, double shippingCharges)
- {
- // Setting the precision to two decimal places
- std::cout << std::setprecision(2) << std::fixed;
- cout << "Spools ready to ship :" << spoolsInStock << endl;
- cout << "Spools on back-order :" << spoolsOrdered - spoolsInStock << endl;
- double subtotal = spoolsInStock * 100;
- cout << "Subtotal ready to ship: $" << setw(10) << subtotal << endl;
- cout << "Shipping and handling :$" << setw(10) << spoolsInStock * shippingCharges << endl;
- double total = (spoolsInStock * 100) + (spoolsInStock * shippingCharges);
- cout << "Total shipping charges :$" << setw(10) << total << endl;
- }
- _______________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement