I am working on a project in which I have to find the largest and smallest integer in a set of 5.
My problem is this: If the list of numbers is ascending in the 'smallest' portion, the program gives me an incorrect answer. Likewise, if the numbers are descending, the 'largest' part is incorrect.
Can anybody take the time to look at my code and give me some pointers? Any help would be appreciated.
Here is the section that's troubling me:
1 2 3 4 5 6 7 8 9 10 11 12 13
if (opt == 1) {
if (num1 > num2) min = num2;
if (min > num3) min = num3;
if (min > num4) min = num4;
if (min > num5) min = num5;
cout<<"The smallest number is "<< min <<"."<<endl; }
if (opt == 2) {
if (num1 < num2) max = num2;
if (max < num3) max = num3;
if (max < num4) max = num4;
if (max < num5) max = num5;
cout<<"The largest number is "<< max <<"."<<endl; }
if (opt == 1) {
if (num1 > num2) min = num2;
if (min > num3) min = num3;
if (min > num4) min = num4;
if (min > num5) min = num5;
cout<<"The smallest number is "<< min <<"."<<endl; }