1 Question

• 11-17-2012
Seniorija
1 Question
Hi dears;

i have written a code for c++ . this code recieve n and then recieve n student grades ,,, and finally it finds the average of grades !

Code:

```#include <iostream> #include <conio.h> using namespace std; int main(){     int n,count=0,sum=0;     float grade,avg;     cout << "How many students grade do you want to input ? \n" <<endl;     cin >> n;     cout << endl;         cout << "Please enter the student grade : \n"<<endl;     while (count<n){     cin >> grade;     cout << endl;     sum += grade;     count++; }   avg = (float)(sum)/(float)(n);     cout << avg;     getch();     return 0; }```
but now i want to calculate the average of the "first (n-1) top grades ! "

now my idea : finiding the min grade between inputed grades and sustract it from sum ... but i dont exactly know how can i find it between inputed grades !!! can u help me ?? tnx;
• 11-17-2012
std10093
Good idea :)

I will make you an example and from this you will be inspired to modify your code ( you see I am fair, I am not stealing you all the fun ;) )

Code:

```#include <iostream> using namespace std; int main () {     int min,n;     cout << "Input number of elements" << endl;     // Input validation!     cin >> n;     cout << endl;     if( n <= 0 )     {         cout << "Non positive input.Exiting..." << endl;         return -1;     }     int array[n];     cin >> array[0];     cout << endl;     // we have only one element     // now, so this is the min     min = array[0];     for(int i = 1 ; i < n ; i++)     {         cin >> array[i];         cout << endl;         // if the element we read         // is smaller than min,         // then assign to min         // this element.         if( array[i] < min )           min = array[i];     }     cout << "min = " << min <<endl;     return 0; }```
Hope this helps:)