Display exactly 10 lines (multipliers 1 through 10)
Use the format: 5 x 3 = 15
Show error message for invalid numbers
Hint 1: Loop Structure
For loop basics:
1. Declare int number; for user input
2. Check if number is between 1 and 20
3. Use: for (int i = 1; i <= 10; i++)
4. Inside loop: calculate number * i
5. Display using cout
Hint 2: Output Formatting
Display format:
• Use cout << number << " x " << i << " = " << (number * i) << endl;
• The parentheses around (number * i) calculate the result
• Each multiplication appears on its own line
• Make sure spacing matches the expected format
Hint 3: Input Validation
Check for valid input:
1. After getting input, use an if statement
2. Check: if (number < 1 || number > 20)
3. If invalid: display error and don't run the loop
4. Otherwise: proceed with the multiplication table
Hint 4: Complete Structure
Full program flow:
1. Ask for the number
2. Get user input with cin
3. Validate: if out of range, show error
4. If valid: use for loop from 1 to 10
5. In each iteration: print formatted line
6. Loop automatically continues until i reaches 10
Test Cases
Input: 5 → Should display 10 lines from "5 x 1 = 5" to "5 x 10 = 50"
Input: 7 → Should display 10 lines from "7 x 1 = 7" to "7 x 10 = 70"
Input: 12 → Should display 10 lines from "12 x 1 = 12" to "12 x 10 = 120"
Input: 1 → Should display 10 lines from "1 x 1 = 1" to "1 x 10 = 10"
Input: 25 → Should display "Invalid input! Please enter a number between 1 and 20."
Example Run (number = 5):
Enter a number (1-20): 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Code Editor
Ready
Output
Console
Console initialized...
Ready for Practice Project 3: Multiplication Table Generator
> Test your code with different numbers
> Use the "Check My Code" button to validate
> Complete all test cases to unlock the Complete button!