Not sure why my bool function isn't working correctly

Currently learning object orientated programming, This programme gets 2 test scores from 3 students and outputs weather or not the student who's name the user typed in passed the year.

I'm having a problem with my bool function at the very end of the programme. The first bool function checks to see if the students name exists. If it does exist, then it goes into a second bool function to see if the students mark is above 80 or not.

Example.

The 3 students and there results for two exams
William = 56 67
Shane = 66 34
Harry = 15 10

If I type in William then the programme works and it says "This student passed"

If I type in Harry then the programme doesn't work and it says "This student doesn't exist"

There seems to be a problem when the bool function that checks to see if the student passed is false. Why is this?

#NOTE# The two bool functions are located in my classes .cpp file. The code that isn't relevant to the question is just to make the programme easier to understand.




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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
           
      
class="centertext"> //main.cpp #include <iostream> #include <iomanip> #include <string> #include "stdafx.h" using namespace std; #include "ProgStudent.h" //Get names and K-numbers from the user //Then instantiate an object and insert in the list for (int i = 0; i < 3; i++) { cout << "Enter a student name and K-number : "; cin >> name >> kNumber; CProgStudent s(name, kNumber); list[i] = s; } int mark; //Allocate marks for project1 cout << "\n\n\n"; cout << "Enter marks for Project1\n"; for (int i = 0; i < 3; i++) { cout << "Enter mark for " << list[i].GetName() << " : "; cin >> mark; list[i].SetProj1Mark(mark); } //Allocate marks for Christmas Exam cout << "\n\n\n"; cout << "Enter marks for Christmas\n"; for (int i = 0; i < 3; i++) { cout << "Enter mark for " << list[i].GetName() << " : "; cin >> mark; list[i].SetChristmasMark(mark); } cout << "\n\n\n"; cout << "Check to see whether a particular student has failed\n"; cout << "Enter a student name: "; cin >> name; for (int i = 0; i < 3; i++) { if (list[i].CheckName(name)) { int mark = list[i].GetTotalMark(); if (list[i].IsAFail(mark)) { cout << "This student passed " << endl; } else cout << "This student failed " << endl; } else cout << "This student doesnt exist "; break; } //Cprogstudent.cpp #include "stdafx.h" #include "ProgStudent.h" using namespace std; bool CProgStudent::CheckName(string searchname) { if (m_Name == searchname) return true; else return false; } bool CProgStudent::IsAFail(int mark) { if (mark > 80) return true; else return false; }



Last edited on
At first glance:
--> where do you declare "list"?
--> what's the point of having a member method ("IsAFail()") that only evaluates a value passed from outside the class? Is it possible that "mark" is also a class property?

Very hard giving any suggestion without a compilable code!
Topic archived. No new replies allowed.