Saith 74 Junior Poster

dariaveltman

please tell what am I doing wrong.

First, please let us know what you are confused about. If you don't know exactly where you are confused in the code or how the code is supposed to work try telling us what you already do know and how you got there. This will help us understand exactly where you were left off as we can continue the discussion from that point instead of possibly repeating something that you may already know.

roc.ky89

I hope this will help you :)
wanna know concept?

I think your post is slightly inappropriate as we should be leading the OP towards his own conclusion instead of telling him the exact answer. By just telling him, they learn nothing. This does not help them later in the future when this type of exercise would have built a better programming structure for the programmer.

Second, you copied and pasted someone elses code. Granted, you did link a site to the page but not until you scroll down do we realize it was copied and pasted from this page. We don't, or at least I don't, expect you to paste it in MLA format, but a simple (CODE WAS COPIED FROM THIS SITE) would have been sufficient.

Saith 74 Junior Poster

This is what I ended up coming up with. First you want to make sure you can open your file. If you cannot open your file, your arrays will automatically be filled with junk. That may be half of your problem.

After that, I just used cout << as a basic step by step debugger to make sure my input into the array was truly valid.

I also changed this from a void() to a main() as I didn't have anything else to go by. Good luck to you and hope this answers your question.

#include <iostream>
#include<fstream>
using namespace std;

int main() {

	int ArrayA[10], ArrayB[20], ArrayN[20];

	ifstream fin;
	fin.open ("1.txt");
	if(fin.fail() ){
		cout << "Input file failed to open.\n";
		exit(1);
	}

	for(int index = 0; index < 10; index++)
		fin >> ArrayA[index];

	for(int index = 0; index < 10; index++)
		cout << "The Array A["<< index << "] " <<ArrayA[index] << endl;


	fin.close();

	ifstream fin2;
	fin2.open("2.txt");
	if(fin2.fail() ){
		cout << "Input file failed to open.\n";
		exit(1);
	}

	for(int index=0; index<20; index++)
		fin2 >> ArrayB[index];

	for(int index = 0; index < 20; index++)
		cout << "The Array B["<< index << "] " <<ArrayB[index] << endl;

	fin2.close();

	//N=A+B to the first 10 in the array	
	for(int index=0; index < 10; index++)
		ArrayN[index] = ArrayA[index] + ArrayB[index]	;	

	// For N[10 - 19] = B[10-19] in the array as ArrayA only goes up to 9, not 19.
	for(int index = 10; index < 20; index++)
		ArrayN[index]  = ArrayB[index]; …