C++ break statement Break appears after an if statement

Introduction

A conditional break, which occurs only if the relational test of the if statement is True.

#include <iostream>
using namespace std;
#include <iomanip.h>
int main()//from   w  ww  . j  a  va 2  s .  co  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)
      {
         break;
      }                 // Exit the loop if no more part numbers.
      cout << "How many were bought? ";
      cin >> quantity;
      cout << "What is the unit price of this item? ";
      cin >> cost;
      cout << "\n" << quantity << " of # " << part_no << " will cost " << setprecision(2) << cost*quantity;
      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;
}



PreviousNext

Related