i wrote a program that shows random grades from 0-100. i want to show the grade valuse but also show only frades from 70 and up. what variable do i have to declare within the int main() function so that it can show the grades from the boolean? how do i get the boolean to show the grades?
You could declare a const int in the main functionfor the passing grade, then check the grade in the array against the passing in the for loop, only printing out if the grade is higher than passing
Do you mean the Pass function to return the letter grade A,B,C (or F?) (char type) or return true or false (bool)? Right now it's mixed - the return statements have char values but the return type is bool. Line 46 - if you put a condition, you need an else if, not else.
basically the boolean suppose to determine a passing grade so yea its a true false (bool). but i want the letter grades to show within the main function. from lines 21 to 23 also. so do i put the letter grades within the main function? how do i put it?
I might make the number to letter conversion its own function (basically what you have for the Pass function now) and then have the Pass function compare the number grade to the passing mark and return true or false. Then in the for loop, check if the Pass function returns true - if it does, then print the number grade and call the number to letter conversion function.
The pass function can compare the number grade to the passing mark (constant integer declared in main and initialized to be 70), returning true if it's a pass, otherwise false.
The for loop can then check the result of this function to decide whether a grade is printed out. A LetterGrade function (or whatever you want to call it) can then convert the number grade to a letter grade (char type).
1 2 3 4 5
for (int index = 0; index < ARRAY_SIZE; index++)
{
if (Pass(quizzes[index],passGrade))//if pass
cout << "quiz[" << index << "] = " << quizzes[index] << ", your grade is " << LetterGrade(quizzes[index]) << endl;
}
int main()
{
const int ARRAY_SIZE = 100;
int quizzes[ARRAY_SIZE];
const int passGrade = 70;
PopulateArray(quizzes, ARRAY_SIZE);
for (int index = 0; index < ARRAY_SIZE; index++)
{
if (Pass(quizzes[index],passGrade))// if pass
cout << "quiz[" << index << "] = " << quizzes[index] << ", your grade is " << LetterGrade(quizzes[index]) << endl;
}
system("pause");
return 0;
}
void PopulateArray(int quizzes[], int size)
{
srand(time(0));
for (int index = 0; index < size; index++)
quizzes[index] = rand() % 101;
}
bool Pass(int grade, const int passGrade)
{
if (grade >= passGrade)
return true;
else
return false;
}
Does the function prototype match the function definition? If you go with the function definition that takes two parameters, you need to update the function prototype at the top.