Conditional Programs
C++ programs that make decisions with if, else if, and else: even/odd, the largest of three, vowels, and leap years, with the edge cases teachers test.
4 programs · open one, then the next
Start with Check for Even Odd- 01Check for Even OddBeginnerCheck whether an integer is even or odd in C++ using the % operator and an if/else. Covers zero, negative numbers, and why == 1 is the wrong test for odd.Open example →cpp#include <iostream> using namespace std; int main() {
- 02Largest Among 3BeginnerFind the largest of three numbers in C++ with an if / else if / else chain and the && operator. Shows why >= matters when two inputs tie for the maximum.Open example →cpp#include <iostream> using namespace std; int main() {
- 03Vowel/Consonant CheckBeginnerCheck whether a character is a vowel, a consonant, or not a letter in C++. Uses tolower from <cctype>, the || operator, and a range test on 'a' to 'z'.Open example →cpp#include <iostream> #include <cctype> using namespace std;
- 04Leap Year CheckBeginnerCheck whether a year is a leap year in C++ with the full Gregorian rule: divisible by 4 but not by 100, or divisible by 400. Worked examples: 1900 and 2000.Open example →cpp#include <iostream> using namespace std; int main() {