Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void sortAscendingOrder(int*, int );
  4. void calculatesAverage(int*,int);
  5. int main()
  6. {
  7.     int* array = nullptr;
  8.     int input;
  9.     std::cout << "Enter the number of testscores you want to enter." <<std::endl;
  10.     std::cin >> input;
  11.    
  12.     array = new int[input];
  13.    
  14.     for(int count =0; count < input; count++)
  15.     {
  16.         std::cout << "Enter the test score" << (count +1) <<":" <<std::endl;
  17.         std::cin >> array[count];
  18.         while(array[count] < 0)
  19.         {
  20.             std::cout <<"You enter a negative number. Please enter a postive number." <<std::endl;
  21.             std::cin >> array[count];
  22.         }
  23.     }
  24.    
  25.     sortAscendingOrder(array,input);
  26.    
  27.     for(int count =0; count < input;count++)
  28.     {
  29.         std::cout << "\n" << *(array+count);
  30.         std::cout << std::endl;
  31.     }
  32.  
  33.     calculatesAverage(array,input);
  34.    
  35.    
  36.    
  37.     return 0;
  38. }
  39. void sortAscendingOrder(int* input,int size)
  40. {
  41.     int startScan,miniIndex,miniValue;
  42.    
  43.     for(startScan =0; startScan < (size-1);startScan++)
  44.     {
  45.         miniIndex = startScan;
  46.         miniValue = input[startScan];
  47.         for(int index = startScan+1;index<size;index++)
  48.         {
  49.             if(input[index] < miniValue)
  50.             {
  51.                 miniValue = input[index];
  52.                 miniIndex = index;
  53.             }
  54.         }
  55.         input[miniIndex]=input[startScan];
  56.         input[startScan]=miniValue;
  57.     }
  58. }
  59.  
  60. void calculatesAverage(int* input, int size)
  61. {
  62.     int total = 0;
  63.     int average =0;
  64.     int lowest= input[0];
  65.     for(int count = 0; count < size; count++)
  66.     {
  67.         total += input[count];
  68.        
  69.     }
  70.     total-=lowest;
  71.     std::cout << "Lowest test score" <<lowest << "is dropped";
  72.     average =total/(size-1);
  73.     std::cout << "Your average is" << average;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement