0

screenshot of code

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

int get_positive_int(string prompt);
int main(void)   
{
{ 
    int i=get_positive_int("Height:");
}
        for (int i = 1; i < n; i++)
            { 
                for (int j = 1; j <= i; j++)
                {
                 printf("#");
                }
             printf("\n");
            }  
}  

int get_positive_int(string prompt)
{
    int n;
    do
    {
       n=get_int("%s",prompt);   
    }
    while (n<1||n>8);
    return n;   
}
0

Compiler errors are usually very direct and self explanatory. In this case, on line 10, you have this:

    for (int i = 1; i < n; i++)

The code is using the variable n as part of the test clause in the for loop setup. Unfortunately, the variable n has not been declared or initialized prior to this point. The compiler doesn't know anything about a variable called n.

You're also going to have a problem with i because it is declared on line 8 and then redeclared on line 10. Perhaps you meant to use n instead of i on line 8? ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

Also, if you have any different or additional problems with this code, please open another question - after trying to identify and then fix it yourself first. ;-)

| improve this answer | |

You must log in to answer this question.

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