#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
int main()
{
int values[7];
std::ifstream iFile;
iFile.open("File.txt", std::ios_base::in);
if(iFile.good())
{
std::string line;
int i = 0;
while(std::getline(iFile, line)) //this assumes the numbers are each on different lines and that there are only 7 numbers
{
std::stringstream ss;
ss << line;
ss >> values[i];
i++;
}
iFile.close();
}
return 0;
}
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
string line;
ifstream myfile;
ofstream newfile;
int low= 999999;
int high = -999999;
float sum=0;
float average=0;
int number;
myfile.open("C:\\Users\\ser\\Documents\\orig.txt");
if (!myfile) //there was an error on open, file not found
{
cout << "Cannot open file, terminating program"<< endl;
system("pause");
exit (1);
}
newfile.open("C:\\Users\\ser\\Documents\\new.txt");
do
{
for (int counter = 1; counter <= 7; counter++)
{
cout << line << "";
newfile << line << "";
}
if (myfile >> number)
{sum += number;
//adds up row in line
}
//validates high and low number
{
high = number;
low = number;
}
while (myfile >> number)
{
if(number > high)
{
high = number;
}
elseif (number < low)
{
low = number;
}
}
// outputs number
average = sum / 7;
cout << "highest number= " << high << endl;
cout << "lowest number= " << low << endl;
cout << "total number= " << sum << endl;
cout << "average= " << average << endl;
newfile << endl;
newfile << "The highest number is: " << high << endl;
newfile << "The lowest number is: " << low << endl;
newfile << "The total of the numbers is: " << sum << endl;
newfile << "The average of the numbers is: " << average << endl << endl;
high = -999999;
low = 999999;
sum = 0;
average = 0;
cout << endl << endl;
}while (!myfile.eof());
cout << endl << endl << "\t complete" << endl;
newfile << endl << endl << "\t complete" << endl;
newfile.close();
myfile.close();
return 0;
}