compare array

I
Last edited on
closed account (3qX21hU5)
Ok so what are you having trouble on? We can't help you without knowing what you are struggling with, and no we won't give you the whole code.

If you are having trouble figuring out where to start here is some advice. Start small like figuring how to get the users input, and break the whole program into smaller manageable pieces. Then go through each and them pieces and add it to the code you already have.

If this is correct, please study it's structure and how it's done. Do not copy and paste - I too am practicing.

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

char readData(int A[], int B[], int& sumA, int& sumB) {
cout << endl << endl << "Array A: " << endl << "-------------" << endl;
	for (int i=0; i<10; i++){
		cout << "Enter number " << i << " for array A: ";
		cin >> A[i];
		sumA += A[i];
	}
cout << endl << endl << "Array B: " << endl << "-------------" << endl;
	for (int i=0; i<10; i++){
		cout << "Enter number " << i << " for array B: ";
		cin >> B[i];
		sumB += B[i];
	}
	if (sumA > sumB)
		return 'a';
	else
		return 'b';
}

void printLarger(char &arrayLarger, int A[], int B[]) {

	if (arrayLarger == 'a'){
	cout << "Array A is larger" << endl << "-----------------" << endl << "It Contained:" << endl << "-----------------" << endl;
		for (int i=0; i<10; i++) {
			cout << A[i] << endl;
		}
	}else{
	cout << "Array B is larger" << endl << "-----------------" << endl << "It Contained:" << endl << "-----------------" << endl;
		for (int i=0; i<10; i++) {
			cout << B[i] << endl;
		}
	}		
}

int main()
{
	int arrayA[10];
	int arrayB[10];
	char arrayLarger;
	int sumA;
	int sumB;
	arrayLarger = readData(arrayA, arrayB, sumA, sumB);
	printLarger(arrayLarger, arrayA, arrayB);
}


EDIT* -- Updated code to read data from user input
Last edited on
thanks for your help, i've figure out how it goes... i've use your coding as example & reference... hope you don't mind.
closed account (3qX21hU5)
Meaning he used your code for his homework lol. Also please don't delete your original post, people search this forum and your topic could have helped them find their answer to their question.
Topic archived. No new replies allowed.