-
Notifications
You must be signed in to change notification settings - Fork 0
/
hmw_2_3.cpp
57 lines (44 loc) · 1.13 KB
/
hmw_2_3.cpp
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
/*
Homework 2_3
Arian Owji
604649619
*/
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
int main()
{
char response = 'y';
double x;
int count = 0;
double sum = 0;
double sumSquares = 0;
while (response == 'y') {
std::cout << "Enter a list of values <of type double>: ";
string line;
getline(cin, line);
stringstream ss(line);
while (!ss.eof()) {
ss >> x;
count++;
sum += x;
sumSquares += (pow(x, 2));
}
double mean = sum / count;
double deviation = (sqrt((sumSquares - ((pow(sum, 2)) / count)) / (count - 1)));
std::cout << "Number = " << count << endl;
std::cout << "Mean = " << mean << endl;
std::cout << "Deviation = " << deviation << endl;
std::cout << endl;
std::cout << "Continue? <y/n> ";
std::cin >> response;
std::cout << endl;
std::cin.get();
count = 0;
sum = 0;
sumSquares = 0;
}
return 0;
}