C declaration expected for "while" loop?
Hey guys, I'm currently learning C and have taken the source code from a tutorial . Since the program terminates after a certain input, I wanted to experiment a bit and try inserting a loop.
I've already tried it with various for and while loops, but every time I get an error for "for" and "while" that a declaration is expected. It also tells me that both while and for generate a syntax error. I've attached a screenshot of it below.
I copied the loops as I found them online, but none of them seem to work. What am I doing wrong?
I am using Microsoft Visual Studio Community 2022 version 17.7.5.
Well, it must be in a class first in C.
In addition, this is an endless loop that does nothing and the code after that is never reached. Probably you want to remove the semicolon, and I don’t know what you want to achieve.
My goal is that the code within the loop, once it is finished, is always executed from the front. At the moment, the program is terminated as soon as you have to calculate a square root. My goal is now that the program, once it has calculated the square root, executes the code again and waits for the next input until the program is terminated automatically by closing the console window.
The semicolon means the loop is over there.
Are you sure you don’t mean anything like C++ here (C is subset of C++)
The question is C, so I assume that the C is.
Take it out, now everything works
The code must be in a function.
Use the main entry spunk main.
int main(void) {
//Your code
}
You must be within a method.
Write before:
int main( int argc, char ** argv ) {
Write after:
}
Has worked so far that he now recognizes the while loop. But now I can’t enter the program anymore. It no longer seems to be up to the program part that stands within the loop.
I removed the “i++” part because it is no longer needed.
At the end of the line with the ‘while’ is a semicolon. That’s the trouble. Take it away.
The block of the While Bow was the empty statement;
There was an endless loop. That’s why he didn’t come to the ‘float number’.
Very typical beginners.
Super, now works. Thank you