0

I am getting an error message of "expression result unused" for the bottom two for loops (specifically h + 1 and s - 1). I've tried looking for through the other questions for an answer but nothing seems to work. At this point I'm stuck. Any thoughts?

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

int main (void)
{
    int n;
    /* Getting the height*/
    printf ("Height: ");
    n = get_int();
    if (n>23 || n<0)
        do
        {
            printf ("Retry\n");
            printf ("Height: ");
            n = get_int();
        }
        while (n>23 || n<0);
    /* Printing the pyramid*/
    int s = n - 1;
    int h = 2;
    for (int i = 0; i < n; i++)
    {
        /* spaces*/
        for ( ; s > 1; s - 1)
        {
            printf (" ");
        }
        /* hash */
        for ( ; h < n*(n + 1) - s; h + 1)
        {
            printf ("#");
        }
    }
}
-1

What are you trying to do with s and h? You just have

s=n-1;
h=2;

and don't do anything with them, thus the error. If you're trying to use them in loops, you should review the syntax of for loops. If you want to increment s by 1 each time you run the loop, beginning with s=n-1 until s>1, for example:

for (int s=n-1; s>1; s++)

This of course assumes s is < 1 to begin with.

You must log in to answer this question.

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