Master control flow and decision making in C++. Learn conditionals, loops, and functions.
Learn to control program execution with conditionals, loops, and reusable functions.
int score = 85; Try different values to test all grade paths (95, 82, 71, 65, 45).char grade; Note: We declare without initializing since we'll assign it in the if-else.if (score >= 90) → Assign grade = 'A' (Excellent)else if (score >= 80) → Assign grade = 'B' (Good)else if (score >= 70) → Assign grade = 'C' (Average)else if (score >= 60) → Assign grade = 'D' (Below Average)else → Assign grade = 'F' (Failing)>= (greater or equal), > (greater), <= (less or equal), < (less), == (equal), != (not equal)Score: 85
Grade: B
Status: PASSED
int score = 85;char grade;if (score >= 90) { grade = 'A'; }else if (score >= 80) { grade = 'B'; }'A' not "A"Review feedback below
for (int i = 1; i <= 20; i++) { ... }int i = 1 - initialization (loop counter starts at 1)i <= 20 - condition (continue while i is 20 or less)i++ - increment (add 1 to i after each iteration)% operator returns the remainder after division.15 % 3 = 0 → 15 is divisible by 3 (no remainder)15 % 5 = 0 → 15 is divisible by 5 (no remainder)7 % 3 = 1 → 7 is NOT divisible by 3 (remainder is 1)i % 3 == 0 evaluates to true, then i IS divisible by 31
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
for (int i = 1; i <= 20; i++) { }if (i % 3 == 0 && i % 5 == 0)else if (i % 3 == 0)else if (i % 5 == 0)else { cout << i << endl; }Review feedback below
int add(int a, int b) { return a + b; }int - return type (the function returns an integer)add - function name(int a, int b) - parameters (inputs the function accepts)return a + b; - returns the sum back to the callerint multiply(int a, int b) { return a * b; }bool isEven(int num) { return num % 2 == 0; }bool (true or false)return sends a value back and exits the function immediately5 + 3 = 8
4 * 7 = 28
Is 10 even? 1
Is 7 even? 0
int add(int a, int b) { return a + b; }int multiply(int a, int b) { return a * b; }bool isEven(int num) { return num % 2 == 0; }add(5, 3) returns 8Review feedback below