Question #52414

Write a C++ program that reads 40 student scores (each between 0 and 20)
into an array, and then prints out the distribution of the scores, i.e., it prints, for each
possible score, the number of students who got that score.
1

Expert's answer

2015-05-29T05:36:06-0400
#include <iostream>
using namespace std;
int main()
{
    int a[40], score[20] = {0};
    for (int i = 0; i < 40; i++)
    {
        cout << "Student" << i + 1 << " score is ";
        cin >> a[i];
        if (a[i] < 0 | a[i] > 20)
        {
            cout << "mistaken score" << endl;
            i--;
        }
    }
    for (int i = 0; i < 40; i++)
    {
        score[a[i]]++;
    }
    for (int i = 0; i < 20; i++)
    {
        cout << score[i] << " students have " << i << endl;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS