Need help with template

I am trying to do this
1
2
3
4
5
Write templates for the two functions minimum and maximum. The minimum function
should accept two arguments and return the value of the argument that is the lesser of
the two. The maximum function should accept two arguments and return the value of
the argument that is the greater of the two. Design a simple driver program that demonstrates
the templates with various data types.


I think dont understand the question (english is my 5th lang)

can some one help me please!!!

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
#include <iostream>

using namespace std;

template <class T1>
T1 minelement (T1 first , T1 last)
{
    if (first ==last)
    {
        return last;
    }
    else
    {
        return first;
    }
}
template <class T2>
T2 maxelement (T2 first , T2 last)
{
    if (first ==last)
    {
        return last;
    }
    else
    {
        return first;
    }
}
int main ()
{
    cout <<"Smallest is : " << minelement(33, 43);
    cout <<"Max is : " << maxelement(39, 29);
    cout <<"Smallest is : " << minelement(33.39, 43.2);
    cout <<"Max is : " << maxelement(39.2, 29.3);
}
you are using the wrong operators. you want:
if(first<last)
Topic archived. No new replies allowed.