Break appears after an if statement. A conditional break, which occurs only if the relational test of the if statement is True. - C++ Statement

C++ examples for Statement:break

Description

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

Demo Code

#include <iostream>
using namespace std;
#include <iomanip>
int main()//  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)
      {
         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;
}

Result


Related Tutorials