Hello.
I am trying to write a c++ program to compute the total, average , highest and lowest score of n students. The code below does almost all, except it gives a memory location of the highest value after sorting an array of marks instead of giving the value itself. Where have I gone wrong?
Code:
//Program to compute students total marks, highest score, lowest score and the //average .
#include <iostream>
#include <algorithm>
using namespace std;
int n (0);
int main ()
{
cout << "Enter the number of students: \n";
cin >> n;
int i (0), mark [n], total (0), av (0);
for (i=0; i < n; i++ ){
cout << "Enter marks\n";
cin >> mark [i];
total += mark[i];
}
av = total / n; // Find an average of all the marks.
sort (mark, mark + n);
cout <<"Lowest: " << mark[0] << ". Highest: " << mark[n] << endl;
cout << "Total Marks: "<< total << endl;
cout << "Average: " << av << endl;
return 0;
}
Bookmarks