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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started