I've been trying to get the Mario problem finished. What appears to me to be a workable solution keeps generating error messages (when I run the compiler) around an "undeclared identifier" (even though I have clearly defined the integer, namely height) and one relating to "expected expression" when using the "height > 0 && < 24" function in a while loop.

I've looked at the other answers on this forum on pset1 Mario but nothing seems to directly address my problem. Why am I getting these errors?

int main(void) 
    do  {
        printf("Enter the height of the pyramid: \n");
        int height = GetInt();
    while (height > 0 && < 24);
  • Please refrain from copy and pasting the entirety of your code! A screenshot of the response from clang would be more helpful. Commented Dec 31, 2014 at 11:54
  • Thanks Christopher and apologies for including unformatted code in its entirety. Clang response: mario.c:16:8: error: use of undeclared identifier 'height' while (height > 0 && < 24); ^ mario.c:16:22: error: expected expression while (height > 0 && < 24); ^ mario.c:19:26: error: use of undeclared identifier 'height' for (int l = 1; l <= height; l++) ^ mario.c:25:29: error: use of undeclared identifier 'height' for (int s = 0; s < height - l; s++) ^ 4 errors generated.
    – adm0501
    Commented Dec 31, 2014 at 11:59

1 Answer 1


In C all variable names have to be declared before they are used. If you try to use the name of a variable or a function that hasn't been declared you will get an "undeclared identifier" error.

  • You issue deals with scoping. To fix your issue you need to declare the variable height before the while lope.

Your code should be the following:

int height;
  do {
    height = Getint();
} while (some condition);
  • Thanks Christopher. The sole error generated now relates to the expression "while (height > 0 && < 24)", specifically the second use of <, and this is preventing the program from running. How can I express this differently to include pyramids of the requisite height (1-23)?
    – adm0501
    Commented Dec 31, 2014 at 13:47
  • you mean to prompt user until height of 1-23 is given? while ((height<0)&&(height>24))
    – ronga
    Commented Dec 31, 2014 at 14:16
  • Sorry for the late response @adm0501. To correct your next problem, a simple fix would be while (height < 1 || height > 23). @ronga you cannot use the && operator because to end the loop both checks would have to evaluate to true which is impossible resulting in a endless loop. A number cannot be less than 1 and greater than 23 at the same time. The || know as the OR operator is needed. Commented Dec 31, 2014 at 17:34
  • you cant literally translate "while [variable] is bigger than 0 and smaller than 24" to code. you need "while [variable] is bigger than 0 and [variable] is smaller than 24" which is written as while(height > 0 && height < 24) Commented May 14, 2020 at 0:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .