Hello,
I'm working on an assignment that requires me to do the following:
"A file contains 6 numbers per line and contains several records. Another file contains 3 numbers per line and several records. Write a program to input each of the numbers, find the highest number, the lowest number, their total and average. Output the numbers, the highest, lowest, total and average to another file."
Output.txt needs to look like this for each numbers per line:
1 2 3 4 5 6
Min: 1
Max: 6
Total: 21
Avg: 3
The problem I'm having with my code is instructing the computer to read the numbers per line, find the desired math results, output it the aforementioned format, and then repeat the algorithm in the next set of numbers. This is my code so far:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main ()
{
//Declaring variables
ifstream inFile;
ofstream outFile;
int NumPerLine, num, count=0;
int sum=0, min=0, max=0, Total=0, Avg=0;
int row=0, col=0, x, y;
//Opening files
inFile.open("input1.txt");
outFile.open("output.txt");
//************************
//Code data manipulation
//************************
cout << "Processing data."
<< endl;
//Read/Write Integer
inFile >> NumPerLine;
outFile << NumPerLine
<< endl;
//While loop reads data
while (!inFile.eof())
{
inFile >> num;
outFile << num << "\t";
sum = sum + num;
count++;
}//Needs to be solved: how do I run math processes(max,min,avg,total)w/ numbers
//at end of line and THEN continue reading and repeating math processes for next line of numbers?
/*Math processes
//Determining Average
Avg = sum / count;
//Determining Sum
sum = num + sum;
//Determining Max
if(x>y)
max=x;
else
max=y;
//Determining Min
if(x<y)
min=x;
else
min=y;*/
//************************
//End of code data manip
//************************
//Close files
inFile.close();
outFile.close();
return 0;
Please help! Thank you.