not sure what is wrong..smallest of three integers

Apr 19, 2016 at 2:37am
this is a bonus challenge Create a function that will return the smallest of three integers entered by the user. Write a program to test it. (Hint: a function argument [or parameter] can be another function call)

this is my code:
#include <iostream>
#include <stdlib.h>

using namespace std;

main()
{
int num1, num2, num3;
using std::cout;
using std::min;
using std::max;
cout << max( max( num1, num2 ), num3 );
cout << min( min( num1, num2 ), num3 );

if ((num1 > num2)&&(num1 > num3))
{
cout<< "Number one is the Largest which is: " << num1 << endl;
}
if ((num2 > num1)&&(num2 > num3))
{
cout<< "Number two is the largest which is: " << num2 << endl;
}
if ((num3 > num1)&&(num3 > num2))
{
cout<< "Number three is the largest which is: " << num3 << endl;
}

if ((num2 < num1)&&(num2 < num3))
{
cout<< "Number two is the smallest which is: " << num2 << endl;
}
if ((num3 < num1)&&(num3 < num2))
{
cout << "Number three is the smallest which is: " << num3 << endl;
}
if ((num1<num2)&&(num1<num3))
{
cout<< "Number one is the smallest which is: "<<num1<<endl;
}
system("pause");
return 0;
}

Im not sure what is wrong with the code. the output is wrong please help
Apr 19, 2016 at 4:25am
you have to include <algorithm> to use std::min and std::max, and num1, num2, num3 seem to be uninitialized.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
    int num1 = 3, num2 = 6, num3 = 1;
    using std::cout;
    using std::min;
    using std::max;
    cout << max(max(num1, num2), num3);
    cout << min(min(num1, num2), num3);

    if ((num1 > num2) && (num1 > num3))
    {
        cout << "Number one is the Largest which is: " << num1 << endl;
    }

    if ((num2 > num1) && (num2 > num3))
    {
        cout << "Number two is the largest which is: " << num2 << endl;
    }

    if ((num3 > num1) && (num3 > num2))
    {
        cout << "Number three is the largest which is: " << num3 << endl;
    }

    if ((num2 < num1) && (num2 < num3))
    {
        cout << "Number two is the smallest which is: " << num2 << endl;
    }

    if ((num3 < num1) && (num3 < num2))
    {
        cout << "Number three is the smallest which is: " << num3 << endl;
    }

    if ((num1 < num2) && (num1 < num3))
    {
        cout << "Number one is the smallest which is: " << num1 << endl;
    }

    system("pause");
    return 0;
}
Topic archived. No new replies allowed.