#include <iostream.h>

// Final Jeopardy Programming Problem
// Input: Our current winnings, followed by the winnings of each
//        of our two competitors (contestants 2 & 3)
// Output: The amount we should wager, according the rules of the
//         problem statement.

// function header:
int prompt_amount(int contestant);

int main()
{
  // get input from user
  cout << "Welcome to the Final Jeopardy round!" << endl;
  int dollars[3];  // current winnings of the 3 contestants
  for( int i = 0; i < 3; i++ )
    dollars[i] = prompt_amount( i+1 );

  // which of the other contestants have more money?
  int larger = dollars[1];
  if( dollars[2] > larger ) larger = dollars[2];

  // decide and output what our wager should be
  if( larger >= dollars[0] )
    cout << "You're not in the lead, and should wager your entire $"
         << dollars[0] << "." << endl;
  else if( dollars[0] > 2*larger )
    cout << "You can comfortably wager $" << dollars[0] - 2*larger - 1
         << "." << endl;
  else
    cout << "You should wager $" << 2*larger - dollars[0] + 1
         << "." << endl;

  return 0;
}

int prompt_amount(int contestant)
{
  int amount;
  while( 1 )
  {
    if( contestant == 1 )
      cout << "Enter your current winnings: ";
    else
      cout << "Enter the current winnings of contestant #"
           << contestant << ": ";
    cin >> amount;
    if( amount >= 0 ) return amount;
    cout << "Please enter a nonnegative integer..." << endl;
  }
}
