creating a bool

can i get some help creating a bool. I am working hard to understand but i dont so i need some help.
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
/ This program calculates student exam average.

#include <iostream>
#include <string>

using namespace std;
void getExamInfo(string, int &);
bool avgCompare(int, int &);


int main()

{
   string prompt = "Enter student's exam grade ";
   string studName;
   int studScore, studAvg, Exam1, Exam2, Exam3, CalAvg;
   char grade;
   

   // Get students first name.
   cout << "Enter student's name. ";

   cin >> studName;

   getExamInfo(prompt, Exam1);
   getExamInfo(prompt, Exam2);
   getExamInfo(prompt, Exam3);
   
   // Original project 1.1 code
   // Get exam 1 score.
   //cout <<  "grade from exam 1 = ";
   //cin >> Exam1;
   // Get exam 2 score.
   //cout <<  "grade from exam 2 = ";
   //cin >> Exam2;
   // Get exam 3 score.
   //cout <<  "grade from exam 3 = ";
   //cin >> Exam3;

   // Calculate exam total.
   studScore = Exam1 + Exam2 + Exam3;

   // Calculate exam total.
   studAvg = studScore/3;

   // End of Project 1

   // Beginning of Project 1.2
   // if else condition
   // statement to display grade letter.
   if (studAvg >= 90) 
	   grade = 'A';
   else if (studAvg >= 80) 
	   grade = 'B';
   else if (studAvg >= 70) 
	   grade = 'C';
   else if (studAvg >= 60)
	   grade = 'D';
   else
	   grade = 'F';

   // Display the average.
   cout <<  "average is " 
	    << studAvg 
		<< " " 
		<<grade; 
   
   // Verify grade
   cout << "Enter students' calculated average ";
   cin >> CalAvg;
  
   // Stop program
   system ("pause");
   return 0; 
}
void getExamInfo(string msg, int &exam)
{
	cout << msg;
	cin >> exam;
}
bool avgCompare(int studAvg, int &CalAvg)
{
return 0;
}


this is my code so far what i want to do is add in a bool that will look at the calculated value of the studAvg and then allow me to enter in a value to compare it to and then say true or false to the enter value being the same as the calculated value. I have my prototype, but i dont have a call or a function for the prototype. I need help with them i am lost and dont know where to start and I and watching videos and referencing several different books but everybody codes differently and it is becoming overwhelming to find simple reference code that i can look at and say "ok i see i need to try step 1...2...3"
Eh, operator== returns bool.
So...

1
2
3
4
bool avgCompare(int studAvg, int &CalAvg)
{
    return studAvg==CalAvg;
}
If you are talking about this function

bool avgCompare(int studAvg, int &CalAvg)
{
return 0;
}

then you can rewrite it the following way

bool avgCompare(int studAvg, int CalAvg)
{
return studAvg == CalAvg;
}
ok I did some work to clarify what i what to do a little better.
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
// This program calculates student exam average.

#include <iostream>
#include <string>

using namespace std;
void getExamInfo(string, int &);
bool avgCompare(int, int &);


int main()

{
   string prompt = "Enter student's exam grade ";
   string studName;
   int studScore, studAvg, Exam1, Exam2, Exam3, CalAvg;
   char grade;
   

   // Get students first name.
   cout << "Enter student's name. ";

   cin >> studName;

   getExamInfo(prompt, Exam1);
   getExamInfo(prompt, Exam2);
   getExamInfo(prompt, Exam3);
   
   // Original project 1.1 code
   // Get exam 1 score.
   //cout <<  "grade from exam 1 = ";
   //cin >> Exam1;
   // Get exam 2 score.
   //cout <<  "grade from exam 2 = ";
   //cin >> Exam2;
   // Get exam 3 score.
   //cout <<  "grade from exam 3 = ";
   //cin >> Exam3;

   // Calculate exam total.
   studScore = Exam1 + Exam2 + Exam3;

   // Calculate exam total.
   studAvg = studScore/3;

   // End of Project 1

   // Beginning of Project 1.2
   // if else condition
   // statement to display grade letter.
   if (studAvg >= 90) 
	   grade = 'A';
   else if (studAvg >= 80) 
	   grade = 'B';
   else if (studAvg >= 70) 
	   grade = 'C';
   else if (studAvg >= 60)
	   grade = 'D';
   else
	   grade = 'F';

   // Display the average.
   cout <<  "average is " 
	    << studAvg 
		<< " " 
		<<grade <<endl; 
   
   // Verify grade
   cout << "Enter students' calculated average ";
   cin >> CalAvg;
   if (CalAvg==studAvg)
   {
	   cout << "Average is Correct.";
   }
   else if (CalAvg!=studAvg)
   {
		cout << "Houston we have a problem!";
   }
  
   // Stop program
   system ("pause");
   return 0; 
}
void getExamInfo(string msg, int &exam)
{
	cout << msg;
	cin >> exam;
}
bool avgCompare(int studAvg, int &CalAvg)
{
return 0;
}


So what i am wanting to do is to create a bool function call avgCompare that will take the place of this portion of code that i just created.
1
2
3
4
5
6
7
8
9
10
11
// Verify grade
   cout << "Enter students' calculated average ";
   cin >> CalAvg;
   if (CalAvg==studAvg)
   {
	   cout << "Average is Correct.";
   }
   else if (CalAvg!=studAvg)
   {
		cout << "Houston we have a problem!";
   }


I am starting to understand why you would want to use functions because code can get way out of control and it is much easier to break any code longer than 6 lines into functions. But that dont mean i know how to write them! LOL!!
Topic archived. No new replies allowed.