doesnt output maximum number

well it should output the index of maximum number:P
#include <iostream>

using namespace std;
const n=10;

int main()

{
int array[n],v=0;

for(int t=0;t<=10;t++)
{
cout<<"type the"<<" "<<t<< " element of an array"<<endl;
cin>>array[t];
}
for(int i=0;i<=10;i++)
{
for(int j=1;j<=10;j++)
{
if(array[i]>array[j])
{
v=array[i];
}
}


}
cout<< v <<endl;
return 0;
}
Hi,

I have modified your code sllightly as you will notice I have reduced your 'find highest' loops
to a single loop because thats all you need.

the only other change I made was in the for statement to ' t < 10' because we start at
zero (0-9) is ten iterations

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

using namespace std;
const int n=10;

int main()

{
	int array[n],v=0;

	for(int t=0;t<10;t++)
	{
		cout<<"type the"<<" "<<t<< " element of an array"<<endl;
		cin>>array[t];
	}

	for(int i=0;i<10;i++)      
	{
		if (array[i] > v)
		{
			v = array[i];
		}
	}
	cout<< v <<endl;
	return 0;
}


Hope this was helpful
Shredded
Topic archived. No new replies allowed.