I was reading your comments and made one more update to add columns.
So here's my advise summed up.
If you open a file, check for success.
Add cout statements to your code for error checking. You can comment them out when your happy all is correct.
Your code is not large but you had several errors that compounded finding the solution.
Try writing a few lines at a time (like a section) and testing the code before you add the next part. Should make it easier to troubleshoot.
When you declare a int or double, always always always set the value to 0, 1, or what ever makes sense to start with.
I may be wrong, but you seem to be confused on how to use a int and double. Read a little more about that or have someone explain the finer details just to make sure you have a good foundation going forward.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <stdio.h>
using namespace std;
const int DATA = 100; // No more than
int main()
{
ifstream fin; // Blaster Size Galactic Standard Units input stream
string getTitle; // Title of ifstream file
double getMeasures; // All the measures in the data set
double determinesMax=0; // Determines Max numeric number in file
double findMin=9999999999; // Determines Min numeric unmber in file
double almostMax=0; // Example for trimmed mean.
int count=0;
fin.open("Blaster.in");
if (fin.is_open())
{
getline(fin, getTitle); // Get the string of the title
cout << getTitle << endl; // Print String
cout << "=============================================================================" << endl; // Text
while (!fin.fail() && !fin.eof())
{ // Calculate unknown amount of values in file
fin >> getMeasures; // Grab largest numeric value
if (getMeasures > determinesMax) // Find Max value
{
almostMax=determinesMax; // Example for trimmed mean.
determinesMax = getMeasures;
}
if (getMeasures < findMin) // Grab lowest numeric value
{
findMin = getMeasures; // Find min Value
}
if (count==10) // Print measures
{
cout << endl;
if (getMeasures<10){cout << " ";}
cout << setprecision (2) << fixed << getMeasures << "\t"; // Print measures
count=0;
}
else
{
if (getMeasures<10){cout << " ";}
cout << setprecision (2) << fixed << getMeasures << "\t"; // Print measures
}
}
}
else
{
cout << "File Bad";
return 1;
}
// output should be floating point (adding a 0 to the end of all values
// Need to print all number in 10 columns of width 8. ????
cout << "\nThe minimum measure is: " << setprecision(2) << findMin << endl;
cout << "The maximum measure is: " << determinesMax << endl;
cout << "The trimmed mean is: " << endl; // calcTrimmedMean - Has to find a trimmed mean....Removing largest and smallest integer
cout << "The second largest number should be " << almostMax << endl;
fin.close();
return 0;
}
|