0

I keep getting 'expression error' when I try to compile my code; any help would be appreciated. Code is as follows:

#include <stdio.h>
#include <cs50.h>

int main(void)

{
    // prompt user for pyramid height between 1 and 8
    int h;
    do
    {
    h = get_int("Height: \n");
    }
    while(h<1 || h>8);


  // loop to print rows equal to height
  int r;
  int c;
  int d;
        //loop to print decreasing number of dots, from 7 to zero
        // loop to print increasing number of hashes, from 1 to 8


  for (r = 0; r < h; r++)
  {
      for (d = 7-r; d >= 0; d-)
      {
          printf(".");
      }
      for (c = 0; c <= r; c++)
      {
         printf("#");
      }
      printf("\n");

  }


}
1

you have an error in the following loop:

for (d = 7-r; d >= 0; d-)

I guess you want to write:

for (d = 7-r; d >= 0; d--)
0

try having a look at your for loops, you probably need to initialise the first variable. Take for instance the first for loop 'for (int r = 0; r < h; r++)'

1
  • Hmm, just tried that and it points out that variable already declared higher in code ("int r;") while continuing to give me "expression error" – bw1968 Dec 16 '20 at 16:41

You must log in to answer this question.

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