### 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.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````#include 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.