Practice basic C++ output concepts with simple exercises on cout, variables, arithmetic expressions, and predicting console output for beginner programmers.
Task: Predict the output.
int x = 10;
int y = 5;
cout << x << endl;
cout << y << endl;
cout << x + y;
Task: Predict the output.
float price = 25.5;
double tax = 5.25;
cout << price << endl;
cout << tax << endl;
cout << price + tax;
Task: Predict the output.
char grade = 'A';
char section = 'B';
cout << grade << endl;
cout << section << endl;
cout << grade + 1;
Task: Predict the output.
string firstName = "Ali";
string lastName = "Ahmed";
cout << firstName << endl;
cout << lastName << endl;
cout << firstName + lastName;
Task: Predict the output.
char letter = 'A';
int number = 5;
cout << letter << endl;
cout << letter + number << endl;
cout << char(letter + number);
Task: Predict the output.
int age = 20;
float height = 5.6;
char grade = 'A';
bool isStudent = true;
cout << age << endl;
cout << height << endl;
cout << grade << endl;
cout << isStudent;
Task: Predict the output.
int a = 20;
int b = 4;
cout << a * b << endl;
cout << a / b;
Task: Predict the output.
int a = 17;
int b = 5;
cout << a % b << endl;
cout << 20 % 3;
Task: Predict the output.
int x = 5;
cout << x << endl;
x++;
cout << x << endl;
++x;
cout << x;
Task: Predict the output.
int x = 10;
cout << x-- << endl;
cout << x << endl;
cout << --x;
Task: Predict the output.
int x = 10;
x += 5;
cout << x << endl;
x *= 2;
cout << x << endl;
x -= 4;
cout << x;
Task: Predict the output.
int a = 10;
int b = 20;
cout << (a > b) << endl;
cout << (a < b) << endl;
cout << (a == b) << endl;
cout << (a != b);
Task: Predict the output.
int age = 20;
int marks = 75;
cout << (age >= 18 && marks >= 50);
Task: Predict the output.
int marks = 40;
int attendance = 80;
cout << (marks >= 50 || attendance >= 75);
Task: Predict the output.
int age = 22;
int marks = 85;
int attendance = 90;
bool result = (age >= 18 && marks >= 50)
|| attendance >= 95;
cout << boolalpha << result;
Task: Predict the output.
int result = 10 + 5 * 2;
cout << result;
Task: Predict the output.
int result = 20 - 12 / 3;
cout << result;
Task: Predict the output.
int result = 20 + 10 / 2 * 3;
cout << result;
Task: Predict the output.
int a = 17;
int b = 5;
int result = a + b % 3;
cout << result;
Task: Predict the output.
const int BONUS = 10;
int salary = 50000;
cout << salary + BONUS;
Task: Predict the output.
const int TAX_RATE = 10;
int price = 1000;
int tax = price * TAX_RATE / 100;
int total = price + tax;
cout << tax << endl;
cout << total;
Task: Predict the output.
double price = 99.75;
int result = (int) price;
cout << result;
Task: Predict the output.
int a = 7;
int b = 2;
double result = a / b;
cout << result;
Task: Predict the output.
int a = 7;
int b = 2;
double result = (double) a / b;
cout << result;
Task: Predict the output.
int code = 65;
char letter = (char) code;
cout << letter;
Task: Predict the output.
int a = 10;
int b = 3;
double result = (double)(a / b);
cout << result;
Task: Predict the output.
double a = 15.8;
int b = (int) a;
double c = b + 2.5;
cout << b << endl;
cout << c;
Task: Predict the output.
int x = 10;
// cout << 20 << endl;
cout << x;
Task: Predict the output.
int a = 5;
/*
cout << 10 << endl;
cout << 20 << endl;
*/
cout << a;
Task: Predict the output.
int a = 10;
int b = 5;
cout << a /* + b */ * 2;
Task: Predict the output.
int number = 10;
// Increase the number
number += 5;
/*
number = number * 2;
cout << number << endl;
*/
cout << number;