3 hours remaining to submit can u help plz!

Hey guys,
I have this assignment to do, but I couldn't do it right
can u help plz ... only 3 hours remaining to submit it and I am totally lost
here is the quastion:


1
2
3
  "Write a C++ function that takes as parameters an int two dimensions array and its size (int rows, int clo). The function should return the maximum element in the array.
Function prototype should be int maxElement( int arr[][], int rows, int clo)
"
Hi All,
So, what did you write till now?
Send the code you wrote and we will help you to do it.
do not be worried about time.
Have Nice Life.
Thank you u for notice @amirtork

and this is what i've done yet
but first you will thought that i am an idiot .. because the programe is totally stuiped
because i am not into this subject at all ... they force us to take it and i don't know why
anyway
look at the quastion and compare it with the answer plz
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
#include <iostream>
using namespace std;

int maxElement( int arr[][], int rows, int clo)
{	int i;
	for(i=0;i<5;i++)
	{int rows;clo;
	int max;
	
		cin>>arr[i][j];
		max=?;\\I don't know how to determine the max 
		

		return max;
	}
 }

 int main()

 {int arr[][];
 int max;
	 int maxElement( int arr[][], int rows, int clo)

	 system("pause");
 } 
Last edited on
I edit it i hope i did it right
but still not working
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
#include <iostream>
using namespace std;

int maxElement( int arr[][], int rows, int clo)
{	int i;
  int j;
	for(i=0;i<5;i++)
	{int rows;
	int max;
	
		cin>>arr[i][j];
		max*=1;
		

		return max;
	}
	for(j=0;j<5;j++)
	{int clo;
	int max;
	
		cin>>arr[i][j];
		max*=1;
		

		return max;
	}
 }

 int main()

 {int arr[][];
 int max;
	 int maxElement( int arr[][], int rows, int clo)

	 system("pause");
 } 
Oops!
i think you don't know exacly what *= work! because you did it for max! and max defined without any first value, so you will have an error here! then listen what you should do.
first, lets get values from user.
for that you should have 2 loops (also its better to have for loop). you should wrote loops to have on int to count the rows and one for count col.
the code will have look like this:
1
2
3
for(int i = 0; i < rows ;  i++)
    for(int j = 0 ; j < col ; j ++)
        cin>>arr[i][j];

after we should have a function that found max.
so if you don't know about functions, you can find them in this site, read about functions and then wrote a function with parameters that you want, then in the function use loops same as i wrote it for you But now we should have and if statement and we don't need cin. so easiest way is have one int var... named max and with value of 0, then in if check if arr[i][j] > max then max = arr[i][j].
I hope you get your answer!.
ATTENTION : if your teacher force you to do this homework , its because he/she want, you learn something so, please start learning your lessons carefully.
Have Nice Life
closed account (2UD8vCM9)
Normally wouldn't spoonfeed this hard, but I hate seeing people fail.

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

int maxElement( int arr[], int rows, int columns)
{
	int MaxElement=0; //Initialize MaxElement (This integer will be returned at the end of the function.)
	for (int elementcount=0; elementcount<(rows*columns); elementcount++) //Loop through all the rows and columns
	{
		if (arr[elementcount]>MaxElement)
		{
			MaxElement = arr[elementcount];
		}
	}
	return MaxElement;
}

 int main()

 {
	 int arr[10][12];
	 int rows=10;
	 int columns=12;

	 //Need to fill in our 2d array with some info
	 for (int rowcount=0;rowcount<(rows); rowcount++)
	 {
		 for (int columncount=0; columncount<columns; columncount++)
		 {
			 arr[rowcount][columncount] = rowcount*columncount;
			 cout << arr[rowcount][columncount] << " "; //Print out each number
		 }
		 cout << endl;
	 }
	 cout << endl << endl;
	


	int max = maxElement( *arr, rows, columns );
	cout << "Max element was:" << max << endl;
	 system("pause");
 } 
Last edited on
Thank you Mr.AmirTork
in my major we don't use this program at all
just a match subject that all the Engineer and IT college must take
Thanx for your help
And you buddy ... @Pindrought
I don't know how I can say "Thank you"
you did the hardest to me that no one does before
Thanx alot and Appreciate your work
Thanx AloOot
Function prototype should be int maxElement( int arr[][], int rows, int clo)

Unfortunately this isn't a valid C++ prototype, so I'm a little concerned. Check what the prototype should be.

PinDrought's solution won't work if the values are all less than zero. You can fix this by changing line 6 to:
 
int MaxElement = arr[0];


Even this is buggy because it will fail if the array has no elements, but the assignment doesn't say what to return in that case.

Hi All again.
thank Mr.Pindrought for solving this problem. But i think its better to send the answer about 1 hour later, if you did it, he wont fail and maybe he learn somethings new :D
and abdu9, read some about structure of c++ and functions, and PLEASE do not just copy and paste the code and submit it, think some about it.
But anyway:
Have Nice Life
Topic archived. No new replies allowed.