Question: Kattis AboveAverage I keep getting Wrong Answer but I don't know what I'm doing wrong. #include #include // for the setprecision command https://www.simplilearn.com/tutorials/cpp-tutorial/cpp-setprecision using namespace

Kattis AboveAverage I keep getting "Wrong Answer" but I don't know what I'm doing wrong.

#include #include // for the "setprecision" command https://www.simplilearn.com/tutorials/cpp-tutorial/cpp-setprecision using namespace std;

int main(){

int c; // cases

cin >> c; for (int i=0; i < c; ++i) { int n; // number of students and their scores cin >> n; int scores [n]; // scores for each class as an array int scoreSum =0; // sum of the scores to be used for the average for (int i = 0; i < n; ++i) { // inputs scores and stores them in array, then adds them together { cin >> scores [i]; scoreSum += scores [i]; } double average = (double) scoreSum / n ; // use a double because we will need 3 decimals double aboveAverage = 0; for (i = 0 ; i < n ; ++i) { if (scores [i] > average){ aboveAverage ++ ; } } cout << fixed << setprecision(3) << (double) aboveAverage / n * 100 << "%" << endl; // must have "fixed" in order to display all 3 decimals } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!