Lesson 5
Decision Making with if and switch
Decision statements allow your program to choose different actions based on conditions.
if...else Example
Example
#include <iostream>
using namespace std;
int main()
{
int mark;
cout << "Enter your mark: ";
cin >> mark;
if (mark >= 50)
cout << "Pass" << endl;
else
cout << "Fail" << endl;
return 0;
}switch Example
Example
#include <iostream>
using namespace std;
int main()
{
int day;
cout << "Enter day number (1-3): ";
cin >> day;
switch (day)
{
case 1: cout << "Monday"; break;
case 2: cout << "Tuesday"; break;
case 3: cout << "Wednesday"; break;
default: cout << "Invalid day";
}
return 0;
}Book Tip:
This short lesson is part of a larger learning path. The full book expands each topic with more explanation, exercises, and projects.