Name your c++ file cpp . PerfectScore_LastNameFirstName.cpp Write a program that
ID: 3602520 • Letter: N
Question
Name your c++ file cpp. PerfectScore_LastNameFirstName.cpp Write a program that contains a function call Input. The Input function should accept at least 2 decimal test scores but no more than 5 test scores can be entered from the user and stores them in an array. '-1' should be used to exit the loop for entering test scores but don’t store any number less than 0. Return the array and number of score entered to main. Inside main, the program should pass the array and the total number of scores to countPerfect. The countPerfect function should count how many perfect (100) scores were entered by the user and return the total to main.
void Input(figure this out);
int countPerfect(double array[], int size);
Once back inside main, the program should display how many scores were entered and how many perfect scores were entered (i.e., scores of 100).
OUTPUT:
Enter a score 0 - 100 (or -1 to quit): 87
Enter a score 0 - 100 (or -1 to quit): -80.5
User entered a number less than 0!!!
Enter a score 0 - 100 (or -1 to quit): 100
Enter a score 0 - 100 (or -1 to quit): 100
Enter a score 0 - 100 (or -1 to quit): 75
Enter a score 0 - 100 (or -1 to quit): -1
There were 4 scores entered include 2 perfect scores. (Printed inside main)
Explanation / Answer
#include <iostream>
using namespace std;
void Input(double array[], int &i) {
for(;;) {
cout<<"Enter a score 0 - 100 (or -1 to quit): ";
cin >> array[i];
if (array[i] == -1 && i > 1) {
break;
}
if(array[i] < 0 && array[i] != -1) {
cout<<"User entered a number less than 0!!! "<<endl;
i--;
}
i++;
}
}
int countPerfect(double array[], int size) {
int count = 0;
for(int i=0;(i<size) ;i++) {
if(array[i] == 100) {
count++;
}
}
return count;
}
int main()
{
double array[5];
int size = 0;
Input(array, size);
cout<<"There were "<<size<<" scores entered include "<<countPerfect(array, size)<<" perfect scores"<<endl;
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.