All pastes #926574 Raw Edit

Something

public text v1 · immutable
·published 2008-03-03 19:27 UTC
rendered paste body
#include <iostream>
using namespace std;
//This program will take a set of inputs, how many decided by the user, and tell the user which was greatest, smallest, or both.
int main(){
    
    int input, greatest, smallest, amount;
    bool keepgoing = true;
    while(keepgoing){
        cout << "How many inputs do you want to enter?: ";
        cin >> amount;
    
        //Run once outside the loop with no initial value to prime greatest and smallest.
        cout << "Enter your first input: ";
        cin >> input;
        greatest = input;
        smallest = input;
        
        //Loop as many times as inputs left to enter, compare smallest and greatest to next input every time and replace as necessary.
        for(int counter = 1; counter < amount; counter++){
            cout << "Enter input number " << counter+1 << ": ";
            cin >> input;
            if(input < smallest)
                smallest = input;
            if(input > greatest)
                greatest = input;
        }
    
        //Ask user what they want to see: greatest smallest or both
        cout << "Enter 1 to see your greatest, 2 to see your smallest, and 3 to see both: ";
        cin >> input;
        
        switch(input){
            case 1:
                cout << "Your greatest number was " << greatest;
                break;
            case 2:
                cout << "Your smallest number was " << smallest;
                break;
            case 3:
                cout << "Your greatest was " << greatest << " and your smallest was " << smallest;
                break;
            default:
                cout << "You did not enter a valid choice.";
                break;
        }
        
        cout << "\nPress 1 to continue, any other number to exit: ";
        cin >> input;
        if(input != 1)
            keepgoing = false;
    }
    cout << "\nPress enter to continue...";
    fflush(stdin);
    cin.get();
}
//How many inputs do you want to enter?: 10
//Enter your first input: 4
//Enter input number 2: 8
//Enter input number 3: 2
//Enter input number 4: 5
//Enter input number 5: 16
//Enter input number 6: 48
//Enter input number 7: 1
//Enter input number 8: 92
//Enter input number 9: 57
//Enter input number 10: 31
//Enter 1 to see your greatest, 2 to see your smallest, and 3 to see both: 3
//Your greatest was 92 and your smallest was 1
//Press 1 to continue, any other number to exit: 0

//Press enter to continue...