Perfect Scores

Hi all. I'm stuck and wanted to see if you good people could help me out.

I have written the following code:

// This program uses function countPerfect to
// detect how many perfect 100 scores were entered.
#include<iostream>
#include<iomanip>
using namespace std;

// Function prototype
int countPerfect(int[], int);

int main()
{
const int NUM_SCORES = 10;
int scores[NUM_SCORES], perfect = 100;

cout << "Enter 10 test scores from 1 - 100: \n";

for (int perfect = 0; perfect < NUM_SCORES; perfect++)
{
cin >> scores[perfect];
}

countPerfect(scores, perfect);

cout << "You entered " << scores << " perfect scores!" << endl;

system("pause");
return 0;
}

/**********************************
* countPerfect *
**********************************/
int countPerfect(int array[], int number)
{
int perfScore = 0;

for (int count = 0; count < number; count++)\
{
if (array[count] == 100)
perfScore = array[count];
}
return perfScore;
}


When the program is run, I get this result:

Enter 10 test scores from 1 - 100:
100
23
54
87
98
90
100
45
67
88
You entered 0012FF2C perfect scores!
Press any key to continue . . .


Any ideas? Thanks in advance.
Hi

Not this way
1
2
countPerfect(scores, perfect);
cout << "You entered " << scores << " perfect scores!" << endl;

But the following

 
cout << "You entered " << countPerfect(scores, perfect) << " perfect scores!" << endl;
Thanks for the help. That solved one problem, but I can't figure out how to get it to display how many times the user entered a perfect score of 100. Using the sample input above, the program should display: "You entered 2 perfect scores!" No matter how many times I enter 100, It tells me that I entered 100 perfect scores.

Once again, thanks in advance.
Last edited on
...therockon7throw ,Have you read the code meticulously???
Alright , i got the correct answer .

#include <iostream>


using namespace std;


int countPerfect(int array[], int number);

int main()
{
const int NUM_SCORES = 10;
int scores[NUM_SCORES], perfect =0;

cout << "Enter 10 test scores from 1 - 100: \n";

for (int perfect = 0; perfect < NUM_SCORES; perfect++)
{
cin >> scores[perfect];
}

perfect=countPerfect(scores, NUM_SCORES);

cout << "You entered " <<perfect<< " perfect scores!" << endl;

return 0;
}

/**********************************
* countPerfect *
**********************************/
int countPerfect(int array[], int number)
{
int perfScore = 0;

for (int count = 0; count < number; count++)\
{
if (array[count] == 100)
perfScore++;
}
return perfScore;
}
Tips: the "perfect" you announced in the before in main fun has no meaning,you should change the name such as Sum_Of_PerfectScores which is used to count how many perfect numbers you entered .
If you can't understand the code above ,just post ,we will help u ~
Last edited on
GREAT! I see where I went wrong, using perfScore = array[count],
instead of perfScore++.

Thank you soooo much for your help.
You're welcome~~By the way, are you american?
Lol this is the second time I've seen this very question in this forum today.
@ Loving Sky

Yes.....Yes I am.
@......I come to this forum only for practicing my English ~~~LOL
Topic archived. No new replies allowed.