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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.