I am trying to calculate the average of 4 integers from a text file and then find the maximum and minimum. This is where i have reached...I am having problems to read the integers and calculate the average..
Code:
#include <cstdlib>
#include <iostream>
#include <fstream.h>
using namespace std;
int main(int argc, char *argv[])
{ char numbers[100];
int sum;
int n,i,firstnum,secondnum,thirdnum,fourthnum,count1,count2;
int average;
int min = 0;
int max = 0;
ifstream streamin;
ofstream streamout;
if (argc!=3)
{ cerr<< "Usage:Program input_file_output_file\n";
exit(1);
}
if(!streamin)
{ cerr <<"Cannot open file!" <<argv[1] <<"for reading" <<endl;
exit(1);
}
if(!streamout)
{ cerr <<"Cannot open file!" <<argv[2] <<"for reading" <<endl;
exit(1);
}
streamin.open(argv[1]);
streamin.getline(numbers,100);
cout <<"The four integers of the input file are: " << numbers <<endl;
streamout.open(argv[2]);
streamin.close();
streamout.close();
Comment