#include <iostream>
using namespace std;
int main() {
int height;
// Prompt the user for input
cout << "Enter an integer (3-25):\n ";//print out instruction for the user
cin >> height;
// Validate the input
if (height < 3 || height > 25) {
cout << "Invalid input! Please enter an integer between 3 and 25.\n" << endl;//to catch error
return 1; // Exit with an error code if found true
}
// Calculate the character to use (ones digit of the height)
char character = (height % 10) + '0';
// Draw the isosceles triangle
for (int i = 1; i <= height; ++i) { // Outer loop controls the rows
// Print spaces for alignment
for (int j = 1; j <= height - i; ++j) {
cout << " ";
}
// Print the characters to form the triangle
for (int j = 1; j <= (2 * i - 1); ++j) {
cout << character;
}
cout << endl; // Move to the next line after each row
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: