Master C++ programming through hands-on coding challenges. Build real programs and develop strong programming foundations.
Write actual C++ code to solve each challenge. Your code is validated for correctness.
#include <iostream> directive tells the compiler to include the iostream library which provides cout for output and cin for input.using namespace std; after your include statement. This allows you to use cout instead of std::cout. Without this, you'd need to prefix all standard library functions with std::.int main() function as its entry point. This is where program execution begins. The function returns an integer (typically 0 for success).cout << "Hello, World!" << endl; to display the message. The << operator is the insertion operator that sends data to the output stream. endl creates a new line and flushes the buffer.cout << "My name is [YourName]" << endl;return 0; to indicate successful program execution. Non-zero return values typically indicate errors.cout stands for "character output" - it writes to the standard output (usually your screen)endl stands for "end line" - it moves the cursor to a new line<< operators: cout << "Hello " << "World" << endl;Hello, World!
My name is [YourName]
#include <iostream>using namespace std;int main() { ... return 0; }cout << "Your text" << endl;Review feedback below
<string> header OR you can use it with iostream. Syntax: string name = "John Doe"; Strings store text/characters and must be enclosed in double quotes.int type stores whole numbers (integers) without decimal points. Range: approximately -2.1 billion to +2.1 billion. Syntax: int age = 25;double type stores decimal numbers (floating-point) with double precision (about 15-16 significant digits). Syntax: double height = 1.75; Use this for measurements, prices, or any value needing decimals.char type stores a single character. IMPORTANT: Characters use SINGLE quotes, not double quotes! Syntax: char grade = 'A';bool type stores only two values: true or false. Used for conditions and flags. Syntax: bool isStudent = true;<< operator: cout << "Name: " << name << endl;Name: John Doe
Age: 25
Height: 1.75
Grade: A
Is Student: 1
boolalpha manipulator.
string name = "Alice"; (double quotes)int age = 30;double height = 1.65;char grade = 'B'; (single quotes!)bool isStudent = false;cout << "Label: " << variable << endl;Review feedback below
int a = 20; and int b = 7; These will be used to demonstrate all arithmetic operations.int sum = a + b; and print the result. The + operator adds two numbers together.int difference = a - b; and print. The - operator subtracts the right operand from the left.int product = a * b; and print. The * operator multiplies two numbers.int quotient = a / b; and print. IMPORTANT: Integer division truncates (removes) the decimal part! 20/7 = 2, not 2.857. For decimal results, use double.int remainder = a % b; and print. The modulus operator returns the REMAINDER after division. 20 % 7 = 6 because 20 ÷ 7 = 2 remainder 6.5 / 2 = 2 (not 2.5)5.0 / 2.0 = 2.5double decimalDiv = (double)a / b; - This casts 'a' to double before division.a = 20, b = 7
Addition: 20 + 7 = 27
Subtraction: 20 - 7 = 13
Multiplication: 20 * 7 = 140
Division: 20 / 7 = 2
Modulus: 20 % 7 = 6
int a = 20; int b = 7;cout << a + b << endl;cout << a - b << endl;cout << a * b << endl;cout << a / b << endl; → Result: 2cout << a % b << endl; → Result: 6Review feedback below