Functions Help

Hello friends,

I am new to C++ I am learning C++ and I came accross this example that I needed some clarification. Every time user inser less than 69 it outputs good. Any ideas?


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
#include <iostream>
using namespace std;

int calculateGrade(int x);
int displayGrade(string message);
int main()
{
int x=0;
displayGrade("Enter your grade");
x= calculateGrade(x);

}
int calculateGrade(int x)
{
	if ((x >= 70)||(x <=100)){
	cout << "Good " << endl;
	}else{
	cout << "Bad" << endl;
}

}
int displayGrade(string message)
{
	
	int x=0;
	cout << message;
	cout << endl;
	cin >> x;
	return x;
}
1
2
3
if ((x >= 70)||(x <=100)){
	cout << "Good " << endl;
}

You have the OR operator here, meaning that the if-statement will be true if either of the conditions are satisfied. 69 is less than 100, making the second condition true, thus outputting "Good".
I see, How would you range it 70 - 100 = good other than that bad ?
You need to use and instead of or.
Topic archived. No new replies allowed.