Array problem, need great help, please

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

//write your functions here



int main ()
{
        //biggestEntry:
        cout << "Testing biggestEntry: ";
        int arr1 [2][3] = {{1, 8, 3}, {4, 7, 3}};
        cout << biggestEntry (arr1, 2, 3) << endl; //prints: 8

        //toTen:
        cout << "Testing toTen: ";
        int arr2 [8] = {5, 3, 1, 6, 10, 1, 30, 100};
        cout << toTen (arr2, 8) << endl; //prints: 4,
        cout << "Testing toTen: ";
        int arr3 [8] = {1, 1, 1, 1, 1, 1, 1, 1};
        cout << toTen (arr3, 8) << endl; //prints: -1
        
        //sixCount:
        cout << "Testing sixCount: ";
        int arr4 [2][6] = {{6, 4, 3, 1, 2, 2666}, {6, 6, 5, 2, 3, 66}};
        cout << sixCount (arr4, 2, 6) << endl; //prints: 8, 
        
        cout << endl;
        
        return 0;
} //main 

1. Write a function called biggestEntry that returns the value of the biggest element in a 2D array with 3 columns.



2. Write a function called toTen that calculates how many entries of a 1D array need to be added to make a sum of ten or more. (Start adding from index 0.)



If the sum of entries in the array never reaches ten, return -1.



3. Write a function called sixCount that returns how many times 6 appears in a 2D array with 6 columns


Alright that is the code that is given in the main. I now have to put functions for these codes that are in the main but im having trouble putting functions for each of them, please can anyone help me on the function codes and no this isnt homework, it is a practice question
This should work for the toTen() function:

1
2
3
4
5
6
7
8
9
10
int toTen(int arr[], int n){
	int sum = 0;

	for(int j = 0; j < n; j++){
		sum += arr[j];
		if(sum >= 10) return ++j;
	}

	return -1;
}
ok thanks that work, now can anybody assist me with the others and please explain how you arrive at the answer because i want to be able to understand it, thank you
You need to make an attempt or you will fail your exams.

You need to make a strong effort to practice the practice questions yourself, first!

Specifically, what problems are you having? Why is your program/solution not working? What don't you understand?
Last edited on
i do make an attempt and trust me ill be ready for my exams in 3 weeks time, dedication and determination will pave way then...its just that i have so much to do now and just need a bit of an assistance thats all
Topic archived. No new replies allowed.