Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- //Variables
- int a;
- int b;
- int c;
- int max;
- double mean;
- int min;
- int array[3];
- bool play = true;
- char answer;
- //Title
- cout << "Integer Analysis App"<< endl << endl;
- //Traps them forever until they say no
- while (play){
- //Asks user for numbers
- cout << "Please enter the following...." << endl;
- //Gets info, with some redudant code
- cout << " Integer 1: ";
- cin >> a;
- array[0] = a;
- cout << " Integer 2: ";
- cin >> b;
- array[1] = b;
- cout << " Integer 3: ";
- cin >> c;
- cout << endl;
- array[2] = c;
- //Calculates the mean
- mean = (a + b + c) / 3;
- //Sets min and max to the first number the user typed in.
- min = array[0];
- max = array[0];
- //Checks for min and max
- for (int i = 0; i < 3; i++){
- //Downgrades the min value if it find a smaller number
- if (min > array[i])
- min = array[i];
- //Upgrades the max value if it finds a bigger number
- if (max < array[i])
- max = array[i];
- }
- //Prints results
- cout << "Analysis Results" << endl;
- cout << "Max: " << max << endl;
- cout << "Min: " << min << endl;
- cout << "Mean: " << mean << endl<< endl;
- //Traps user if they type dumb stuff, looping them over in this mini loop. Good answers will free them, sending the the beginning of the program or ending it
- while (answer !='y' || answer != 'Y'){
- //Gets users response
- cout << "Play again? ";
- cin >> answer;
- cout << endl;
- //Frees the user and send them back to begining of the main program while loop
- if (answer =='y' || answer == 'Y')
- break;
- //Ends the program by breaking the main while loop
- if (answer == 'n' || answer == 'N')
- play = false;
- //Breaks the dumb question check while loop. The program will end because we set play to false
- if (answer == 'n' || answer == 'N')
- break;
- }
- }
- cout << "Good bye!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement