max num and min num c++

I can't seem to figure out the correct formula to find the max number in a series of 4 numbers or the min number for that matter. This is what I have so far but it is very far off...Any suggestions?
[code]
cout << "The maximum number is: " << endl;
maximum = i;
for (i = 1; i < 4; i++)
{
if (i > maximum)
maximum = i;
}
cout << maximum << endl;

cout << "The minimum number is: " << endl;
minimum = i;
for (i = 1; i > 4; i--)
{
if (i < minimum)
minimum = i;
}
cout << minimum << endl;
[/code]

Comments

  • You are on the right track. Generally such code would be written like this:

    [code]
    #define N 4

    int main()
    {
    int array[N] = { ... }; /* numbers go here */
    int maximum;

    maximum = array[0];
    for(i=1; i maximum)
    {
    maximum = array[i];
    }
    }
    }[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion