I'm trying to figure out a code that can determine the largest number, smallest number, second largest number, and second smallest number for ay set of numbers inputted. Here is my code. I am having issues mainly due to the initialization of variables. I'd appreciate any help!
My code:
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main(){
string buffer;
unsigned n;
double min = 1, max = 0;
double min2 = 1, max2 = 5;
cout << "How many integers will you enter? ";
cin >> n || die("Input failure ");
cout << "OK type the " << n << " integers, non #'s to quit: ";
for (unsigned count = 0; count < n; count++){
double num;
cin >> num;
if (min > num){
min = num;
}
else if (max < num){
max = num;
}
else if (num >= max2 && num <= max){
max2 = num;
}
else if (num >= min2 && num <= min ){
min2 = num;
}
} cout << "The largest number is: " << max << endl;
cout << "The smallest number is: " << min << endl;
cout << "The second smallest number is: " << min2 << endl;
cout << "The second largest number is: " << max2 << endl;
cin >> buffer;
}