Using I/O Streams and Arrays.


Write a program that:
1. Ask the user for names of the two iput files and a name of an output file. The two input files contain integers in any order. Eachimput file contains no more than 20 integers.
2.Create two arrays of integer of size 20. One for each input file.
3. Read in the numbers from the imput files into the arrays respectively.
4. Find the smallest and the largest numbers from the two input files and writes the answers into a third file - output file.
5. Find the average of all numbers and write to the third file (output file.) Each input file contains a list of numbers (no more than 20 numbers) of type int separated by a space.
(The number of data in each file is not fixed. They also could be in any order)


Any help is much appreciated. I have seeked out all possible help I have around me, I have sat in front of this computer for hours. I just need some kind of break through or I might go crazy!





What have you gotten done already? Can't really help till we know where you're stuck.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <fstream>



int main()
{
using namespace std;
char first_infile[21], second_infile[21], out_file;
ifstream in_stream;
ofstream out_stream;


cout<<"Please give me the first input file name (maximum of 20 characters)."<<endl;
cin>> first_infile;
cout<<"Ok i will use this file name:"<<first_infile<<endl;
cout<<"Please give me a second input file name (maximum of 20 characters)."<<endl;
cin>> second_infile;
cout<<"Ok i will use this file name:"<<second_infile<<endl;
cout<<"Now please give me an output file name (maximum of 20 characters)."<<endl;
cin>> out_file;
cout<<"Ok i will use this file name:"<<out_file<<endl;


in_stream.open(first_infile);
if(in_stream.fail())
{
cout<<"Input file opening failed.\n";
exit(1);
}


in_stream.open(second_infile);
if(in_stream.fail());
{
cout<<"Input file opening failed.\n";
exit(1);
}

const int ARRAY1=20, ARRAY2=20;
int number1[ARRAY1], int number2[ARRAY2];


This is what I have so far. I am just confused how to implement the array witht he input file that I am getting from the user?
Topic archived. No new replies allowed.