Guest User

Untitled

a guest
Aug 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<iomanip>
  5. using namespace std;
  6.  
  7. void read(vector<double>&t)
  8. {
  9. double r;
  10. cout << "Skriv in dina siffror" << endl;
  11. while( cin >> r)
  12. t.push_back (r);
  13. }
  14.  
  15. void compute(double minsta, double storsta, double medel, const vector<double>&t)
  16. {
  17. double total;
  18. int h=0;
  19. for(int i=0; i <= t.size(); i++)
  20. {
  21. total=total+t[h];
  22. h++;
  23.  
  24. if (minsta = 0)
  25. {
  26. minsta=t[h];
  27. }
  28.  
  29. else if (minsta > t[h])
  30. {
  31. minsta=t[h];
  32. }
  33.  
  34. else if (storsta = 0)
  35. {
  36. storsta=t[h];
  37. }
  38.  
  39. else if (storsta < t[h])
  40. {
  41. storsta=t[h];
  42. }
  43.  
  44. }
  45. medel=total/h;
  46. }
  47.  
  48. int main()
  49. {
  50. vector<double>vec;
  51. read(vec);
  52.  
  53. if (vec.size() < 1)
  54. cout << "ingen indata" << endl;
  55.  
  56. else
  57. {
  58. double minsta;
  59. double storsta;
  60. double medel;
  61.  
  62. compute(minsta, storsta, medel, vec);
  63.  
  64. cout << minsta << endl << storsta << endl << medel << endl;
  65. }
  66.  
  67. system("pause");
  68. return 0;
  69. }
Add Comment
Please, Sign In to add comment