score array

I have to write a modular program that accepts at least 10 integer test scores from the user and stores them in an array. Then main should display how many perfect scores were entered (scores of 100), using a value-returning countPerfect function to help it. Input Validation: Do not accept scores less than 0 or greater than 100.

Am I on the right track or what am I missing?
int main()
{
//declare section
double power[10];
int super;
int happy=10;

cout<<"Please enter the 10 grades"<<endl;

for(super=0; super<happy;super++)
{
while((power < 0) && (power > 100))
{
cout<<"Please enter a positive number: "<<endl;
}
cout<<"Enter grade for test #"<<super+1<<":";
cin>>power[super];
}
return 0;
}
@kdmpenguin

Well, the main problem I see is your code while((power < 0) && (power > 100)). The input of power[super] CAN NOT be less than 0 AND greater than 100 at the same time. Use OR, which is ||. Also, you need to put the cout << "Enter ... " <<endl; and the cin input before the while check. This should get you moving in the right direction.
I changed it to OR, but i still get an error on the (power>100) and for the second can i use an IF statement to display the scores of 100?

what does using a value-returning countPerfect function to help it mean? Do i have to use a void countPefect at the top and then in main use it to call how many perfect scores there were?
Is this closer to it being right, i know there are errors but is this the right idea?

#include <iostream>
using namespace std;

void int countPerfect();

int main()
{
//declare section
int power[10];
int super;
int happy=10;

cout<<"Please enter the 10 grades"<<endl;

for(super=0; super<happy;super++)
{
cout<<"Enter grade for test #"<<super+1<<":";
cin>>power[super];

while((power<0) || (power>100))
{
cout<<"Please enter a positive number: "<<endl;
}
}
return 0;
}

int countPerfect()
{
int perfect;
if (power==100)
{
cout<<"There are"<<perfect<<"scores"<<endl;
cout<<"Thank you for using the program"<<endl;
}
return 0;
}
@kdmpenguin

Here's your code. It accepts the 10 grades, and rejects the input if it's less than 0 or greater than 100.
After inputting the 10 grades, use the function to check each one. If the value is 100, have a variable to increase by one upon return. After all 10 checked, print out the variable that shows how many perfect scores there were..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Score Array.cpp ....

#include <iostream>

using namespace std;

int main()
{
	//declare section
	int power[10];
	int super, grade, i;
	int happy=10;

	cout<<"Please enter the 10 grades"<<endl;

	for(super=0; super < happy; super++)
	{
		cout<<"Enter grade for test #"<<super+1<<" : ";
		cin>>grade;
		while((grade < 0) || (grade > 100))
		{
			cout << "Please enter a positive number: "<<endl;
			cin >> grade;
		}
		power[super] = grade;
	}
	for ( i=0;i<10;i++)
	{
		cout << "Grade " << i+1 << " = " << power[i] << "..." << endl;
		// Now write the function to see if power[i] equals perfect score
		// 
	}	
	return 0;
} 
is it something like this?

#include <iostream>
using namespace std;

void countPerfect();

int main()
{
	//declare section
	int power[10];
	int super, grade, i;
	int happy=10;

	cout<<"Please enter the 10 grades"<<endl;

	for(super=0; super < happy; super++)
	{
		cout<<"Enter grade for test #"<<super+1<<" : ";
		cin>>grade;
		while((grade < 0) || (grade > 100))
		{
			cout << "Please enter a positive number: "<<endl;
			cin >> grade;
		}
		power[super] = grade;
	}
	countPerfect();
	return 0;
}
	void countPerfect()
{
	int grade;

	for (grade=0;grade<1;grade++)
	{
		cout<<"There were "<<grade<<" perfect grades"<<endl;
		grade++;
	}

}
Last edited on
A little like that.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Score Array.cpp : Defines the entry point for the console application.

#include <iostream>

using namespace std;

int countPerfect(int );

int main()
{
	//declare section
	cout << " ";
	for( char a='A';a<'H';a++)
		cout  << a << " ";
	cout << endl;
	for ( int i = 1; i < 8;i++)
		cout << i << endl;
	int power[10];
	int super, grade, i, perfect = 0;

	cout<<"Please enter the 10 grades"<<endl;

	for(super=0; super < 10;super++)
	{
		cout<<"Enter grade for test #"<<super+1<<" :";
		cin>>grade;
		while((grade < 0) || (grade > 100))
		{
			cout << "Please enter a positive number: "<<endl;
			cin >> grade;
		}
		power[super] = grade;
	}
	for ( i=0;i<10;i++)
	{
		cout << "Grade " << i+1 << " = " << power[i] << "..." << endl;
		perfect += countPerfect(power[i]);
	}
	cout << "There were " << perfect << " scores of 100.." << endl; 
	
	return 0;
} 

int countPerfect(int grade)
{
	if (grade==100)
		return 1;
	else
		return 0;
}
okay, thank you for your help
Topic archived. No new replies allowed.