Help me please~

I'm new to C++.Today I want to write some lines to pick the min data and its index from a array .So I write a function and I use the construct return the result.But some error appears .I can't figure it out .Somebody help me please .Thank you in advance.
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
#include <iostream.h>

	struct result
	{
		int Min;
		int index;
	};

 Fmin(int arg[],int len)
{

	result re;
	re.Min = arg[0];
	for(int i=1;i<len;i++)
	{
		if(arg[i]<re.Min)
		{
			re.Min = arg[i];
		}
		i++;
	}
	return re;
}

void main()
{
	result resl;
	int age[] = {34,91,83,56,29,93,56,12,88,73};
	resl = Fmin(age,10);
	
	cout <<resl.Min<<"    "
		 <<resl.index<<endl;
}
The function Fmin() is missing the return data type.

You are missing "using namespace std;" after the #include's.

Always post error messages. Copy and paste them here. If you don't have a compiler at hand, try www.ideone.com.
Fmin(int arg[],int len) - what's the return type? Should be:

result Fmin(int arg[],int len)

When do you set re.index? Never. You should.

Other issues are that you're using an old style of C++ that many modern compilers will refuse to work with (for example, void main()). This is not a problem unless you ever intend to do any programming with other people or as a job.
Thank you for your answers. It worked after Moschops's suggestion. Yeah I am using the old style but I am learning the new one. The guys around me all use the old one. Just say that they are all out of date. Again thank you!!

You are missing "using namespace std;" after the #include's.


As an aside, the old style iostream.h did not recognise the std namespace, so this is only necessary is one switches to the modern iostream (without the .h).
Topic archived. No new replies allowed.