Greatest/Lowest

Hello everyone,

I need to input 3 numbers and find the greatest/lowest number using if statements.

So far I have:

#include <iostream>
int main()
{
int n1;
int n2;
int n3;
int lowest;
int greatest;

greatest = n1;

if ( n2 >= greatest )
{
n2 = greatest;
}

if ( n3 >= greatest )
{
n3 = greatest;
}

lowest = n1;

if ( n2 <= lowest )
{
n2 = lowest;
}
if ( n3 <= lowest )
{
n3 = lowest;
}

std::cout << "Greatest=" << greatest << std::endl;
std::cout << "Lowest=" << lowest << std::endl;
return 0;
}

I specifically have to use if statements.

Any thoughts?

Thanks
Last edited on
closed account (2UD8vCM9)
Not sure what you're asking, your code does what you're requesting.

However, keep in mind, before you do greatest = n1, you have to fill in a value for n1, n2, and n3.

Perhaps something like

1
2
std::cout << "Enter your 3 numbers." << std::endl;
std::cin >> n1 >> n2 >> n3;


Before you say greatest=n1
Thanks, figured it out... my n2 > lowest statements were reversed...
Right to left, not left to right...
Topic archived. No new replies allowed.