Output the right letters

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?

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
  #include <iostream>
#include <cstdlib>
#include <time.h>
#include <string>
using namespace std;

void PopulateArray(int[], int);
bool Pass(int);
int whoPass;

int main()
{
	const int ARRAY_SIZE = 100;
	int quizzes[ARRAY_SIZE];
	
	
	

	PopulateArray(quizzes, ARRAY_SIZE);
	
	for (int index = 0; index < ARRAY_SIZE; index++)
		cout << "quiz[" << index << "] = " << quizzes[index] 
		<< ", your grade is a(n) " << Pass(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)
{
    if (grade >= 90)
		return 'A';
	else if (grade >= 80)
		return 'B';
	else if (grade >= 70)
		return 'C';
	else (grade >= 60); 
 }
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.
can you really show mw where to put everything? im still kind of a beginner
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.

1
2
3
4
5
6
7
bool Pass(int grade, const int passGrade)
{
    if (grade >= passGrade)
        return true;
    else
        return 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;
	}
is it suppose to be like this ? theres a error in line 8 and 22. what do i add in the bool on top before the main?

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <string>
using namespace std;

void PopulateArray(int[], int);
bool Pass(int);


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

Last edited on
The function prototype and definition need to match.

bool Pass(int);
bool Pass(int grade, const int passGrade)

You'll need to put in a definition for the LetterGrade function - it would be close to what you had before with the letter grades.
the error shows that the boolean has too much inputs on it
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.
Topic archived. No new replies allowed.