Combining a template recursion into one file?

Header:
1
2
3
4
5
6
7
8
9
10
11
template < class T >
T minimum ( T value1, T value2)
{

	T minimumValue = value1;

	if (value2 < minimumValue)
		minimumValue = value2;

	return minimumValue;
}



.cpp file
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
#include <iostream>
using namespace std;

#include "minimum.h"

int main()
{

	int int1, int2;
	cout << "Enter two integer values: " << endl;
	cin >> int1 >> int2;

	cout << "The minimum value is: " 
		<< minimum (int1, int2)<< endl; 

	double double1, double2;

	cout <<"\nEnter two double values: " << endl;
	cin >> double1 >> double2;

	cout << "The minimum value is: "
		<< minimum (double1, double2) << endl;

	char char1, char2;
	cout << "\nEnter two character values: " << endl;
	cin >> char1 >> char2;

	cout << "The minimum value is: "
		<< minimum (char1, char2) << endl; 
	return 0;

}


How do I combine these 2 files into one?
?

Replace the line #include "minimum.h" with the contents of minimum.h ?
Do I simply do that? Also, what do I do if I don't want to use recursion?

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
#include <iostream>
using namespace std;

template < class T >
T minimum ( T value1, T value2)
{

	T minimumValue = value1;

	if (value2 < minimumValue)
		minimumValue = value2;

	return minimumValue;
}

int main()
{

	int int1, int2;
	cout << "Enter two integer values: " << endl;
	cin >> int1 >> int2;

	cout << "The minimum value is: " 
		<< minimum (int1, int2)<< endl; 

	double double1, double2;

	cout <<"\nEnter two double values: " << endl;
	cin >> double1 >> double2;

	cout << "The minimum value is: "
		<< minimum (double1, double2) << endl;

	char char1, char2;
	cout << "\nEnter two character values: " << endl;
	cin >> char1 >> char2;

	cout << "The minimum value is: "
		<< minimum (char1, char2) << endl; 
	return 0;

}
Now, I'm not using recursion. I'm not supposed to. This is for homework and my brain is going crazy! I don't know how to turn the code I already made into using it to find the minimum in vectors. Can someone point me in the right direction?
You need a loop. Assume that the minimum value is the first one in the vector. Then, compare the second value
against that minimum. If the second value is less than your assumed minimum, then assume that the second value
is the minimum. Repeat for the 3rd element, then 4th element, and so forth until you compare the last element.
At that point, your assumed minimum is the minimum value.

If that is not helpful enough, there are a number of posts around here regarding finding the minimum or maximum
values in an array/vector.
Topic archived. No new replies allowed.