C++ examples for Data Type:float
Gets inventory information from user and prints an inventory detail listing with extended totals.
#include <iostream> using namespace std; #include <iomanip> int main()// ww w. ja v a 2 s . com { 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; }