What 5 numbers? That is, how are they stored? Are you using an array, or are they 5 separate variables, or are you trying to prompt the user for five numbers then determine the largest and smallest from that?
What 5 numbers? That is, how are they stored? Are you using an array, or are they 5 separate variables, or are you trying to prompt the user for five numbers then determine the largest and smallest from that?
Sorry I mean "5 integers". Prompt the user for 5 integers.
Ok,
Use a for loop and an array to prompt and store the int's.
Then define two variables, largest and smallest.
Use a second for loop to iterate through the array and compare the current position to the largest encountered number and the smallest encountered number. If the current value is larger than the largest, set the largest to the current. Same logic for the smallest one...
Ok,
Use a for loop and an array to prompt and store the int's.
Then define two variables, largest and smallest.
Use a second for loop to iterate through the array and compare the current position to the largest encountered number and the smallest encountered number. If the current value is larger than the largest, set the largest to the current. Same logic for the smallest one...
Ummmmm ok.... I haven't learn array/loop... I'm like at the beginning of learning C++. The question I asked you was part of my book exericse. :\
Alright.
Try creating three variables, greatest, smallest, and userIn.
You can then use cin to get user input and store it to userIn.
All you have to do then is compare userIn to greatest. If userIn is greater than greatest, update greatest to equal userIn. If userIn is less than smallest, update smallest to equal userIn. Do this five times and you are good to go.
The first time you do that though, you need to set greatest and smallest to userIn as the first input will be both the largest and smallest input so far...
I don't really want to do your homework for you... But I'll get you started in the right direction.
1 2 3 4 5 6 7 8 9 10 11
...
int userIn, max, min; //define vars
cin>>userIn; //Get 1st number
max=userIn; //Set Maximum to first number
min=userIn; //Set Minimum to first number
cin>>userIn; //Get next number
if (userIn>max) //Check if user entered amount bigger than current maximum
max=userIn; //If user entered amount bigger than current maximum, update current maximum
if (userIn<min) //Check if user entered amount smaller than current minimum
min=userIn; //If user entered amount smaller than current minimum, update current minimum
...