I've just solved my mario.c pset1, everything seems to work, but when I enter a value over 23 like 50 or so, the code is still running and drawing the pyramid then re-prompt the height. I've tried to add an if statement but doesn't work. What's wrong with my code?
#include <stdio.h> #include <cs50.h> void repeat(int y, char s) { for (int i = 0; i < y; i++, printf("%c", s) ); } int main(void) { int height; do { printf ("height: "); height = GetInt(); } while ( height < 0 || height > 23 ); int x = 0; if (height < 0 || height > 23){ for (int i = 0; i < height; i++) { int total = height + 1; int num_spaces = total - x; int num_hashes = 2 + x; repeat(num_spaces-2, ' '); repeat(num_hashes, '#'); x++; printf("\n"); } } }