fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <algorithm>
  5. using std::cout;
  6. using std::cin;
  7. using std::vector;
  8. using std::endl;
  9. using std::sort;
  10.  
  11.  
  12.  
  13. int main(){
  14. vector<double> notes;
  15. cout<<"Enter some notes and hit ctrl+D followed by an <enter> to stop: ";
  16. double input;
  17. while(cin >> input){
  18. notes.push_back(input);
  19. }
  20.  
  21. cout<<endl<<"Entered notes: ";
  22. for(int i=0; i<notes.size(); ++i){
  23. cout<<notes[i]<<" ";
  24. }
  25. sort(notes.begin(), notes.end());
  26.  
  27. cout<<endl<<"Min: "<<notes[0]<<" Max: "<<notes[notes.size()-1];
  28. double sum, avg = 0;
  29. for(int i=0; i<notes.size(); ++i){
  30.  
  31. sum +=notes[i];
  32. }
  33. avg = sum/notes.size();
  34.  
  35. cout<<"\nThe avg is: "<<avg;
  36.  
  37.  
  38.  
  39.  
  40. }
Success #stdin #stdout 0s 3436KB
stdin
2
6
4
8
2
stdout
Enter some notes and hit ctrl+D followed by an <enter> to stop: 
Entered notes: 2 6 4 8 2 
Min: 2 Max: 8
The avg is: 4.4