bool argument

how do I write this code properly to display the amount of students that passed using bool
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
51
52
53
54
 #include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

void PopulateArray(int[], int size);
bool Fail(int grade);

int main()
{

	const int ARRAY_SIZE = 100;
	int quizzes[ARRAY_SIZE];

	int failed = 0;

	PopulateArray(quizzes, ARRAY_SIZE);
	
	*  if(Fail)true;
	  {
	  failed =+ 1;
	  }

	cout << "The ammount of students that passed are: " << failed << endl;
	

	system("pause");
	return 0;
}

void PopulateArray(int quizzes[], int size)
{
	srand(time(0));

	for (int a = 0; a < size; a++)
	{
		quizzes[a] = rand() % 101;
		cout << "quizzes [" << a << "] = " << quizzes[a] << " failed " << Fail(quizzes[a]) << endl;
    }
	


}

bool Fail(int grade)
{
	if (grade < 70)
	{
		return true;
	}
	else
		return false;
}

* where help is needed or so i believe
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
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

void populateArray(int arr[], int size);
bool fail(int grade);

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

    int failed = 0;
    populateArray(quizzes, ARRAY_SIZE);

    for(int i = 1; i <= ARRAY_SIZE; i++){
        if(fail(quizzes[i])){
            cout << "Student at element " << i << " scored " << quizzes[i] << ". That is a passing grade." << endl;
        } else{
            failed++;
            cout << "Student at element " << i << " scored " << quizzes[i] << ". That is not a passing grade." << endl;
        }
    }

    cout << endl;
    cout << failed << " people failed." << endl;
    return 0;
}

void populateArray(int arr[], int size)
{
    srand(time(0));

    for(int i = 0; i < size; i++){
        arr[i] = rand() % 101;
    }
}

bool fail(int grade)
{
    if(grade < 70)
        return false;
    else
        return true;
}


Okay, first thing first. Your function prototype is missing the array name.
void PopulateArray(int[], int size)

Next if(Fail)true is invalid. The way you would test if it's true or false is by if(Fail()) because its returning either true or false.

Next. failed =+ 1; is setting failed equal to positive 1. I'm assuming you're trying to increment it every time, you do that like this failed += 1. Or even simpler just failed++;

Then everything else just kind of confused me.
That's why I posted my version of your program. Hopefully it can help you. If you need me to clarify anything don't hesitate to ask. I'm new to programming too ^_^
Last edited on
You know what I totally scrambled alot of the description and the code since i rushed it in class then just tried to add things to make it work causing more problems. Thank you for your help i see where i had things backwards and completely off which was why my output failed. The Fail bool was just me putting something there to show what i kind of wanted I had no idea of how to actually implement it, so i thank you for that to and the great explanation :).
Topic archived. No new replies allowed.