In: Computer Science
Write a program in C++ 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.
Intro into C++
#include<iostream>
using namespace std;
int main()
{
int scores[100];
int numOfScores, passingGrade, countOfPassingScrores=0;
double passPercent;
cout<<"\nHow many scores you want to enter? ";
cin>>numOfScores;
if(numOfScores>100)
cout<<"\nMaximum number of scores allowed is 100. Try
again..";
else
{
for(int i=0;i<numOfScores;i++)
{
cout<<"\nEnter a score: ";
cin>>scores[i];
}
cout<<"\nEnter the passing grade: ";
cin>>passingGrade;
for(int i=0;i<numOfScores;i++)
{
if(scores[i]>=passingGrade)
countOfPassingScrores++;
}
passPercent =
(((double)countOfPassingScrores/(double)numOfScores))*100.00;
cout<<"\nThe number of passing scores are:
"<<countOfPassingScrores;
cout<<"\nThe percent of scores that are passing is:
"<<passPercent<<"%";
}
return 0;
}
OUTPUT: