Select Git revision
Analyze.c 1.29 KiB
#include <iostream>
#include <string>
#include <fstream>
int main(int argc, char **argv)
{
if (argc == 1) //No filename was entered.
{
std::cout << "No_Filename_Given._Exiting." << std::endl;
return 1;
}
if (argc > 2) //Too many arguments given.
{
std::cout << "More_than_one_filename_given._Exiting." << std::endl;
return 1;
}
std::ifstream infile(argv[1]);
if (infile)
{
{float a,Min=1000000,Max=0,Sum=0,Mean,Entries=0; //Define as float a, Min, Max, Sum, Mean, Entries, and set initial values for Min, Max, Sum, Entries.
while (infile >> a) //Set a == value on the next line in file.
{
if ( a < Min ) Min = a; //Set Min to smaller of previous value or a.
if (a > Max ) Max = a; //Set Max to Larger of previous value or a.
Entries = Entries++; //Increase entry count by one.
Sum = Sum + a; //Add current a value to running Sum.
Mean = Sum/Entries;}
std::cout << "Entries: " << Entries << "_;";
std::cout << "Max: " << Max << "_;";
std::cout << "Min: " << Min << "_;";
std::cout << "Sum: " << Sum << "_;";
std::cout << "Mean: " << Mean << "." << std::endl; // Report Values
return 0
;}}
else
{
std::cout << "Can_not_Open_File. " << argv[1] << std::endl; //Unable to open file.
return 1
; }
}