daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     double *students, nummovies=0,average=0.0,total=0.0,temp,hopp=0,count=0,oldhopp,oldcount=0;
  6.     int numstudents=0,mode=0;  
  7.     cout << "how many students were surveyed?\n";
  8.     cin >> numstudents;
  9.     students = new double[numstudents];
  10.     for (int x=0;x<numstudents;x++)
  11.     {
  12.         cout << "how many movies has student " << x+1 << " seen?\n";
  13.         cin >> students[x];    
  14.     }
  15.  
  16.     for (int y=0;y<numstudents;y++)
  17.     {
  18.         total += students[y];
  19.     }
  20.     average = total/numstudents;
  21.     cout << "the average number of movies seen was " << average << endl;
  22.      
  23.     for(int i=0;i<numstudents;i++)
  24.     {
  25.         for(int j=i+1;j<numstudents;j++)
  26.         {
  27.             if(students[i]>students[j])
  28.             {
  29.                 temp=students[j];
  30.                 students[j]=students[i];
  31.                 students[i]=temp;
  32.  
  33.             }
  34.  
  35.         }
  36.     }
  37.     if(numstudents%2==0)
  38.         cout << "the median is " << (students[numstudents/2]+students[numstudents/2-1])/2 << endl;
  39.     else
  40.         cout << "the median is " << students[numstudents/2] << endl;
  41.    
  42.     for (int u=0;u<numstudents;u++)
  43.     {
  44.         hopp = students[u];
  45.         count = 1;
  46.         for (int l=u+1;l<numstudents;l++)
  47.         {
  48.             if (hopp == students[l])
  49.                 count++;
  50.         }
  51.         if(count > oldcount)
  52.             {
  53.                 oldhopp = hopp;
  54.                 oldcount = count;
  55.             }
  56.     }
  57.    
  58.     cout << "the mode is " << oldhopp << endl;
  59.    
  60.    
  61.     system("pause");
  62.     return 0;
  63. }
RAW Paste Data
Top