Break doesn't printf the proper solution


#1

Hi there,

I just started going through the book and as I type in the example in the book, the output never shows “The answer is 10”, it always says “The Answer is 0”

here is my code:

#include <stdio.h>

int main(int argc, const char * argv[])
{
int i;
for (int i = 0; i < 12; i++)
{
printf(“Checking i = %d\n”, i);

    if (i + 90 == i * i)
    {break;}
    
}
printf("The answer is %d\n", i);


return 0;

}

I keep going back and forth between what I typed and the book and I can’t seem to see where my typo is. Xcode is letting me run the code, but I can’t seem to get it where printf(“The answer is %d\n”, i); pulls the i from the break, it just pulls from 0.


#2

and nevermind, I solved it. in line 2 I had listed for (int i…) instead of just for (i…)