Algorithmic Thinking

Let's take our program modification one step at a time, starting with just the top two weights. Figure 4.1 is one possible way to handle this version of the problem.

Figure 4.1. Finding the top two weights, first try (code\pump1a.cpp)
#include <iostream>
using namespace std;

int main()
{
  short CurrentWeight;
  short HighestWeight;
  short SecondHighestWeight;
  cout << "Please enter the first weight: ";
  cin >> CurrentWeight;
  HighestWeight = CurrentWeight;
  SecondHighestWeight = 0;
  cout << "Current weight " << CurrentWeight << endl;
  cout << "Highest weight " << HighestWeight << endl;

 while (CurrentWeight > 0)
  {
  cout << "Please enter the next weight: ";
  cin >> CurrentWeight;
  if (CurrentWeight > HighestWeight)
   {
   SecondHighestWeight ...

Get C++: A Dialog Programming with the C++ Standard Library now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.