I want to find the lowest number of the four, but this looks kinda wierd , isnt there a smarter and shorter way to do it?
That is what I have:
int findlowest(int one, int two, int three, int four) {
int output = one //as of now , we will be outputting one , except if we find a lower score.
if(output > two) { out = two;} // if output is proven to be bigger than two, two is our new output.
if(output > three){ output = three;} //same operation with three
if(output > four){ output = four;} // same operation with four
return output;
}
std::min in C++ std::min is defined in the header file <algorithm> and is used to find out the smallest of the number passed to it. It returns the first of them, if there are more than one.
Comparing three integer variables is one of the simplest program you can write at ease. In this program, you can either take input from user using scanf() function or statically define in the program itself. We expect it to be a simple program for you as well.
To check if a variable is equal to all of multiple values, use the logical AND (&&) operator to chain multiple equality comparisons. If all comparisons return true , all values are equal to the variable.
c++11:
int minimum = std::min( { 1,2,3,4,5 } );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With