-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pt4.cpp
57 lines (36 loc) · 1001 Bytes
/
Pt4.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
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;
/*
Abshir Mohamed
8-13-2018
HW6
*/
void calcStats(int[],int);
int main() {
int answer;
do{
cout<<"How many students were surveyed? (no negative numbers)"<<endl;
cin>>answer;
}while(answer<0);
int *movies = new int[answer], watched;
for(int i = 0;i<answer;i++){
do{
cout<<"How many movies did student number "<< i+1<< " watch?"<<endl;
cin>>watched;
}while(watched<0);
movies[i] = watched;
}
calcStats(movies,answer);
return 0;
}
void calcStats(int arr[],int size)
{
int sum = 0;
for(int i = 0;i<size;i++)
sum += arr[i];
cout<<"The total number of movies watched was " << sum<<" movies"<<endl;
cout<<"The average number of movies watched was " << (sum / size) <<" movies"<<endl;
}