Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ question Write a program that declares an array of 100 integers named scores

ID: 3822457 • Letter: C

Question

C++ question

Write a program that declares an array of 100 integers named scores[]. Prompt the user for how many scores they want to enter. Then read in the specified number of ints and store them in the array. Then prompt the user for a passing grade. Use a for loop to go trough the array and count how many scores are passing. Print the count of how many passing scores, and also print a double that is the percent of scores that were passing. Note that although the scores array is allocated to store 100 ints,only the number of scores specified by the user are actually stored, so generally only part of the array storage capacity is used,

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
int scores[100];
int n;
int grade;
cout<<"Enter how many scores t be entered: ";
cin >> n;
cout<<"Enter "<<n<<" scores: "<<endl;
for(int i=0; i<n; i++){
cin >> scores[i];
}

cout<<"Enter a passing grade: ";
cin >> grade;
int count = 0;
for(int i=0; i<n; i++){
if(scores[i] >= grade) {
count++;
}
}
double average = (count * 100) / (double)n;
cout<<"Number of passing grades: "<<count<<endl;
cout<<"Average: "<<average<<endl;
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter how many scores t be entered: 10                                                                                                                                                                                                                                 

Enter 10 scores:                                                                                                                                                                                                                                                       

11 22 33 44 65 66 77 88 99 100                                                                                                                                                                                                                                         

Enter a passing grade: 60                                                                                                                                                                                                                                              

Number of passing grades: 6                                                                                                                                                                                                                                            

Average: 60

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote