Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ifstream inputfile;
  9. string fileName;
  10. double sum = 0;
  11. double average = 0;
  12. double minimum = 0;
  13. double maximum = 0;
  14. double x = 0;
  15. int counter = 0;
  16.  
  17.  
  18. cout << "Enter the file name " << endl;
  19. cin >> fileName;
  20.  
  21. inputfile.open(fileName);
  22.  
  23. while(inputfile >> x)
  24. {
  25. if(counter == 0)
  26. {
  27. minimum = x;
  28. maximum = x;
  29. }
  30. if(x < minimum)
  31. {
  32. minimum = x;
  33. }
  34. if(x > maximum)
  35. {
  36. maximum = x;
  37. }
  38. sum+=x;
  39. counter++;
  40. }
  41. average = sum / counter;
  42. cout << "The minimum is " << minimum << endl;
  43.  
  44. cout << "The maximum is " << maximum << endl;
  45.  
  46. cout << "The average is " << average << endl;
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement