0
How I can keep minimum and maximum of numbers from cin ?
I have numbers from cin but I don't know how can I stock them and keep the maximum and the minimum. Example : 12 34 54 3 4 Maximum : 54 Minimum : 3
3 Answers
+ 6
Ipang Yeah, I think he wants the last option you mentioned.
+ 5
Hatsy Rei Thanks, I hope we guessed right, its been 5+ hours and yet no response from the OP, and no code included either to show the actual intention đ
I'm gonna give it a blank shot anyways, hope the OP cared to respond with it.
#include <iostream>
int main()
{
int n;
// initial value for min & max
// is the first input value
std::cin >> n;
int min_value {n}, max_value {n};
// read successive values and compare
while(std::cin >> n)
{
if(n > max_value) max_value = n;
if(n < min_value) min_value = n;
}
std::cout << "Min value: " << min_value
<< "\nMax value: " << max_value
<< std::endl;
return 0;
}
+ 3
* What do you mean by "stock them"? you mean all the numbers are kept in memory?
* Do you want a flexible storage for the numbers or static one (user defines size)
* Do you need to have the min & max updated as new number is entered?