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;
}
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;
}
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..