C++ do while loop Gets inventory information from user
#include <iostream> using namespace std; #include <iomanip.h> int main()/*from w w w . j a v a 2 s . c o m*/ { int part_no, quantity; float cost, ext_cost; cout << "*** Inventory Computation ***\n\n"; // Title // Get inventory information. do { cout << "What is the next part number (-999 to end)? "; cin >> part_no; if (part_no != -999) { cout << "How many were bought? "; cin >> quantity; cout << "What is the unit price of this item? "; cin >> cost; ext_cost = cost * quantity; cout << "\n" << quantity << " of # " << part_no << " will cost " << setprecision(2) << ext_cost; cout << "\n\n\n"; // Print two blank lines. } } while (part_no != -999); // Loop only if part number is not -999. cout << "End of inventory computation\n"; return 0; }