Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cmath>
- using namespace std;
- // getting the file name.
- string getFileInfo ()
- {
- string dogo;
- string fileName;
- ifstream infile;
- while (!(dogo == "the price is right"))
- {
- cout << "Enter a file name: " << endl;
- cin >> fileName;
- infile.open (fileName);
- if ((infile))
- {
- break;
- }
- cout <<endl << "tis not possible." << endl;
- }
- // calculating the mean of all the numbers.
- return fileName;
- };
- double calculateMean(string fileName)
- {
- double mean;
- double dog;
- double seagull;
- mean = 0;
- ifstream infile;
- infile.open (fileName);
- while (infile)
- {
- infile >> seagull;
- dog = seagull + dog;
- }
- dog = dog - 34;
- mean = dog / 20;
- return mean;
- };
- // calculatoing the minimum of all the numbers.
- int calculateMin(string fileName)
- {
- int min;
- int seagull;
- int dog;
- ifstream infile;
- infile.open (fileName);
- infile >> seagull;
- while (infile)
- {
- infile >> dog;
- if (seagull > dog)
- {
- seagull = dog;
- }
- }
- min = seagull;
- return min;
- }
- // displaying the infomration gained.
- void displayInfo(double mean, int min)
- {
- cout << "The mean is:\t" << mean << endl;
- cout << "the min is:\t"<< min << endl;
- };
- int main()
- {
- // starting functions in main.
- string fileName = getFileInfo ();
- double mean= calculateMean(fileName);
- double min = calculateMin(fileName);
- displayInfo(mean, min);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement