Build error

Asked

Viewed 56 times

-4

I started AI recently and I don’t get much of this... The idea was to use the while to show us all even numbers up to 100 but is always giving error and could not fix this yet.

while (i <= 100) {
   i += 1;
   if (i % 2 == 0)
       prinft('\n%d', i)
}
  • 1

    I don’t understand why the dial, the question is within the scope. Even being a basic syntax error, he was helped by the community. I believe that is the purpose of Stackoverflow. And even though the solution is not useful to users in the future, it may have been useful to the author of the question at that time.

  • @Felipepaetzold read the description in Marelinho.

  • @bigown understand, but what if the solution presented helped him who asked the question?

  • 1

    @Felipepaetzold is still a typo, it won’t help anyone else, there’s no reason why it stays open, no new answer will give a better solution.

2 answers

2

You typed wrong, it’s not prinft but printf.

You can use the module operator as well...

while (i <= 100) {
   i += 1;
   if (i % 2 == 0)
       printf('\n%d', i)
}
  • 'Cause I’ve corrected it, but by the way, what do I have to do for the final figure to give me 100 instead of 102?

  • Your code uses while (i <= 100).. the <= is inclusive, ie, it will perform the while scope when the i is equal to 100. And within the scope you are adding 2 to the value of i, resulting in 102. Change the <= for <.

  • Okay, thanks for the help ;).

0

You wrote the name of the printf function wrongly.

The correct is:

printf("Algum texto");

Try to pay more attention to the errors that the compiler shows you. He’s saying

"Undefined Reference to prinft".

That is, either you wrote it wrong or you didn’t include the right libraries. In case you had misspelled

  • Thanks, I didn’t even notice and I was trying to fix the rest.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.