Practice identifying and correcting common C++ beginner mistakes in syntax, variables, operators, and output with simple debugging exercises.
For each question:
Important: Try to find the mistake yourself before checking the solution.
if StatementTask: Find and fix the mistake in the following program.
int x = 10;
if (x > 5);
{
cout << "Greater";
}
Task: Find and fix the mistake in the following program.
int x = 10;
if x > 5
{
cout << "Greater";
}
Task: Find and fix the mistake in the following program.
int marks = 60;
if (marks >= 50)
{
cout << "Pass";
}
else (marks < 50)
{
cout << "Fail";
}
Task: The program should print Eligible for people aged 18 or older.
int age = 16;
if (age >= 18)
{
cout << "Eligible";
}
else
{
cout << "Not Eligible";
}
cout << "Eligible";
Task: The program should print Pass when marks are 50 or above. Identify the mistake.
int marks = 50;
if (marks > 50)
{
cout << "Pass";
}
else
{
cout << "Fail";
}
Task: The program should print the greater number. What is the mistake?
int a = 10;
int b = 20;
if (a > b)
{
cout << b;
}
else
{
cout << a;
}
Task: The program should print Even for an even number. What is the mistake?
int n = 7;
if (n % 2 == 1)
{
cout << "Even";
}
else
{
cout << "Odd";
}