Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- double *students, nummovies=0,average=0.0,total=0.0,temp,hopp=0,count=0,oldhopp,oldcount=0;
- int numstudents=0,mode=0;
- cout << "how many students were surveyed?\n";
- cin >> numstudents;
- students = new double[numstudents];
- for (int x=0;x<numstudents;x++)
- {
- cout << "how many movies has student " << x+1 << " seen?\n";
- cin >> students[x];
- }
- for (int y=0;y<numstudents;y++)
- {
- total += students[y];
- }
- average = total/numstudents;
- cout << "the average number of movies seen was " << average << endl;
- for(int i=0;i<numstudents;i++)
- {
- for(int j=i+1;j<numstudents;j++)
- {
- if(students[i]>students[j])
- {
- temp=students[j];
- students[j]=students[i];
- students[i]=temp;
- }
- }
- }
- if(numstudents%2==0)
- cout << "the median is " << (students[numstudents/2]+students[numstudents/2-1])/2 << endl;
- else
- cout << "the median is " << students[numstudents/2] << endl;
- for (int u=0;u<numstudents;u++)
- {
- hopp = students[u];
- count = 1;
- for (int l=u+1;l<numstudents;l++)
- {
- if (hopp == students[l])
- count++;
- }
- if(count > oldcount)
- {
- oldhopp = hopp;
- oldcount = count;
- }
- }
- cout << "the mode is " << oldhopp << endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment