two dimensional array error

this code is working but im having troubles in some part
the program will ask for scores in double type and will be stored in an array of double type, that works, but when i get to displaying the highest entered score
it only returns an int type value,
where could be the problem?

thanks!


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
using namespace std;

void main()
{

	int rows,cols,i,j;

	double score[100][100],sum=0,ave=0.0;
	cout<<"Enter rows: ";
	cin>>rows;
	cout<<endl;
	cout<<"Enter column: ";
	cin>>cols;
	cout<<endl;

	cout<<"You will enter "<<rows*cols<<" elements in a ["<<rows<<"]x"<<"["<<cols<<"] matrix";
	cout<<endl<<endl;


	for ( i=0;i<rows;i++)
	{
		for ( j=0;j<cols;j++)
		{
			do
			{
			cout<<"["<<i<<"]["<<j<<"] :";
			cin>>score[i][j];
			sum+=score[i][j];
			}
			while(score[i][j]<0 || score[i][j]>100);
		}
		cout<<endl;
		
	
		
	}
	
	cout<<endl<<endl;
	cout<<"You entered: "<<endl;

	for ( i=0;i<rows;i++)
	{
		for ( j=0;j<cols;j++)
		{

			
			cout<<score[i][j]<<"\t";
					
		}
		cout<<endl;
	}


		ave=sum/(rows*cols);
		cout<<endl;
		cout<<"The average mean score is: "<<ave;



	
	for ( i=0;i<rows;i++)
	{
		for ( j=0;j<cols;j++)
		{
			
			if (score[i][j]>score[i+1][j+1])
			{
				int temp=score[i][j];
				score[i][j]=score[i+1][j+1];
				score[i+1][j+1]=temp;
			}
							
		}
		cout<<endl;
	}
	



	cout<<"The highest score is: "<<score[i][j];
	cout<<endl;
	cout<<"The lowest score is: "<<score[0][0];
	cout<<endl;
		




}
it only returns an int type value,
where could be the problem?
On line 69 (int temp). Better write swap(score[i][j], score[i+1][j+1]); instead of line 69 - 71

Lines 62 - 76 don't sort correctly. It's very likely that you won't find the highest/lowest. To find highest/lowest only you don't need to sort at all.
coder777 thanks i got it! i wasnt able to notice it, thanks again!!!!!
Topic archived. No new replies allowed.