Click to See Complete Forum and Search --> : C++


T
02-24-2001, 09:38 PM
How can I find the lowest out of five inputed numbers????

Indiana Jonethon
02-24-2001, 11:32 PM
"T" <blueman2@xta.com> wrote:
>
>How can I find the lowest out of five inputed numbers????

my solution:

int someNum[5];
int lowest = 0;

cout<< "input numbers"<< endl;
for (int i =0; i<5; i++)
{
cin >> someNum[i];
}

for (i = 0; i<5; i++)
{
if(someNum[i] < someNum[lowest])
{
lowest = i
}
}
cout << "lowest number is " << someNum[lowest];

Danny Kalev
02-25-2001, 03:52 AM
you have two ways. Either sort them using one of the standard sorting
algorithms, say qsort or std::sort (or write one on your own, if that's
what your instructor expects you to do), or use the min() algorithm
recursively:

#include <algorithm>

int main()
{
int n1=3,n2=78,n3=34,n4=2,n5=6;
using std::min;
int lowest = min((min(min(n1,n2),n3),n4),n5);
}

Danny