forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.22.cpp
30 lines (24 loc) · 783 Bytes
/
4.22.cpp
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>
int main() {
int grade;
std::cin >> grade;
std::cout << (
grade > 90 ? "high pass"
: grade > 75 ? "pass"
: grade >= 60 ? "low pass"
: "fail"
) << std::endl;
// Note that the conditional operator is right associative, meaning that the
// operands are grouped from right to left.
if (grade > 90)
std::cout << "high pass" << std::endl;
else if (grade > 75)
std::cout << "pass" << std::endl;
else if (grade >= 60)
std::cout << "low pass" << std::endl;
else
std::cout << "fail" << std::endl;
// The `if` statements are relatively easy to understand when the conditions
// do not have much braches.
return 0;
}