Need help reading data into 3 arrays!!!!!!!

I have to write a c++ program ram to declare 3 arrays, ArrayA, ArrayB, ArrayC, to hold 25 integers each. Write code to do the following –in this order.

Read data into ArrayA. Print ArrayA, including the array name and using a counter to number the elements as shown below, with columns aligned.

Array A
1. 59
2. 234
3. 90
4. 1285...etc.

Repeat for Array B.

Compute the Sum and the Average of all values in ArrayA and ArrayB. (Can do in one loop orin two.)Print results with appropriate headings.

Compute the contents of ArrayC by adding ArrayA & ArrayB and storing the answer for each location in the corresponding location in ArrayC. Print ArrayC as above.

Recalculate ArrayC by comparing the corresponding locations in ArrayA and ArrayB and placing the maximum value in ArrayC. Print ArrayC as above.Use your own data for testing. (HINT: get it working for a small array, e.g 5 elements) You will be provided a single file with 50 integersnext week. Read the first 25 into ArrayA and the next 25 into ArrayB.

You can use for loops for all of your looping.

So far I have this:

int main()
{
const int ArrayA = 26;
int numbers[ArrayA];
int count = 1;
ifstream infile;
ofstream outfile;

// open file
infile.open("Text.txt");
outfile.open("output.txt");

while (count < ArrayA && infile >> numbers[count])
{
count++;
}

// close input file
infile.close();

// read numbers
outfile << "Array A" << "\n";
for (count = 1; count < ArrayA; count++)
{
outfile << count << "." << setw(6);
outfile << numbers[count] << " " << "\n";
}

outfile.close();
return 0;
}


I need help reading data into ArrayB and ArrayC.
Last edited on
> I need help reading data into ArrayB and ArrayC.
It's the same code.

Or it could be.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void readArray( int numbers[], int size, ifstream &in ) {
    for ( int i = 0 ; i < size ; i++ ) {
        in >> numbers[i];
    }
}

int main ( ) {
    int A[10], B[10];
    ifstream infile;
    // open file
    infile.open("Text.txt");
    readArray(A,10,infile);
    readArray(B,10,infile);
}

I can't use void and need to use two different data files, each containing 25 items
need to use two different data files
You got an example how to open and read one file, do you need a second example how to open a second file?
Like holidays in France and the translator app contains the example "I'd like 100 gram ham", to get 200 grams you have to enter the butcher's shop twice.
I can't use void and need to use two different data files, each containing 25 items


@salem c gave you an example showing things can be done in C++. He* did not do your homework for you. He didn't try to do your homework. He gave you enough information such that, with a little bit of thought, you could take the principles that he showed you and extend them to do your own homework.



*I assumed gender. No disrespect intended if I assumed incorrectly.
Topic archived. No new replies allowed.