// File: WhileBoolFlagFunctionSwitchSentinel.CPP // Sentinel Terminated; Switch Statement Used; Boolean Flag; While Loop // Find the Extremes in a List of integers // Use a boolean flag to facilitate all data input into the program loop // Method of Iteration: for loop // Note that Data is always input directly before the sentinel is checked. #include #define False 0 #define True 1 #define Sentinel -999 using namespace std; // Return a Character to identify if the present value is a new extreme // + ==> New Max - ==> New Min char Relation(int,int,int); int main() {int Value,Min,Max,ExtremesInit=False; // Prompt For First Value cout << "Enter the 1st Integer. " << Sentinel << " Quits >"; // Read first Value Before Loop cin >> Value; while (Value != Sentinel) { if (!ExtremesInit) { // Only Correct Method of Initializing Min and Max: // Set equal to initial Value Max=Min=Value; ExtremesInit=True; ; } else switch(Relation(Value,Min,Max)) { case '+': Max=Value; break; case '-': Min=Value; break; default: // Default Action: Do Nothing...Could (should) have left this part out break; } // Read subsequent Values At End of Iteration cout << "Enter the Next Integer. " << Sentinel << " Quits >"; cin >> Value; } if (ExtremesInit) cout << "Minimum:" << Min << "\tMaximum:" << Max << endl; return(0); } char Relation(int N,int Minimum,int Maximum) {if (N>Maximum) return('+'); if (N