0
I made this code but it keeps giving endless loop and I can’t fix...
#include <stdio.h>
int main (){
int x, z;
while("x=100; x!=65; x-=5"){
z=x*x;
printf("%d --> %d\n", x, z);
}
}
0
I made this code but it keeps giving endless loop and I can’t fix...
#include <stdio.h>
int main (){
int x, z;
while("x=100; x!=65; x-=5"){
z=x*x;
printf("%d --> %d\n", x, z);
}
}
3
I’m pretty sure it’s because of the quotes:
"x=100; x!=65; x-=5"
Remove them:
while(x=100; x!=65; x-=5){
values between quotation marks in C are char *
, which means you didn’t pass the variables, but yes char
, and pro loop break needs to pass a value like "false
", yet while does not work with ;
, you probably want to use the for
:
for (x=100; x!=65; x-=5){
z=x*x;
printf("%d --> %d\n", x, z);
}
Or if it’s the while
you can use it like this:
x=100;
while (x!=65){
z=x*x;
printf("%d --> %d\n", x, z);
x-=5;
}
Browser other questions tagged c loop while
You are not signed in. Login or sign up in order to post.
I have tried to put it error when compiling and is asking for a ) after (x=100 6 15 [Error] expected ')' before ';' token
– Gustavo Carvalho
@Evelynndelrey edited the answer.
– Guilherme Nascimento
What you sent me worked, but like most of my class did x=100; and x-=5; inside while(), how would it look? wanted to know what I did wrong ...
– Gustavo Carvalho
@Evelynndelrey that as far as I know doesn’t exist in
C
, you must have been confused. Documentation MSDN https://msdn.microsoft.com/pt-br/library/y1tscb5y.aspx– Guilherme Nascimento
probably man, Rigadão by help <3
– Gustavo Carvalho