#loop working, but everything within if-else statements won't execute

56 messages · Page 1 of 1 (latest)

sturdy brook
#

like the title says, when I execute the code with the "flags" enable, the flags with print. Nothing within the if-else statement will print, any help appreciated.

forest fjordBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

sturdy brook
#
#include <stdio.h>
#include <unistd.h>




int main(){
char welcome[] = "\" *****{Welcome to "
           "C291 Fall 2021 @ IU}"
              ", %%%%%% Golden Rule: S"
                 "tart working on ever"
                    "ything as early as p"
                       "ossible %%%%%% Thanks *"
                          "**** \n\"";

printf(welcome);

int num = 100;

for(;;)
{
/*      printf("I am a flag\n");
        printf("%04d\n", num);
        */
if(num % 2 == 0){
        printf("%04d", num);
        printf("*");
        sleep(1);
        printf("*");
        sleep(1);
        printf("*");
        sleep(1);
        printf("*");
        sleep(1);
        printf("*");
}
else{
        printf("%04d\n", num);




}
}
return(0);
}//end bracket`
#

oh and expected output:

prisma thistle
#

y is this so cursed

sturdy brook
#

Welcome Message
0100****
0099
0098****

sturdy brook
prisma thistle
#

but why is it like as messy as possible

#

and why is there a comment for the end bracket

#

and why is there a giant space

#

and why is there no indent

twin knollBOT
#
Compiler Output
Killed - processing time exceeded
prisma thistle
#

what haev you done

sturdy brook
#

oh

#

idk

prisma thistle
#

its because you made an infinite loop

sturdy brook
#

the professor said to make an infinite loop

#

hold on

prisma thistle
#
#include <stdio.h>
#include <unistd.h>




int main(){
char welcome[] = "\" *****{Welcome to "
           "C291 Fall 2021 @ IU}"
              ", %%%%%% Golden Rule: S"
                 "tart working on ever"
                    "ything as early as p"
                       "ossible %%%%%% Thanks *"
                          "**** \n\"";

printf(welcome);

int num = 100;

/*      printf("I am a flag\n");
        printf("%04d\n", num);
        */
if(num % 2 == 0){
        printf("%04d", num);
        printf("*");
        printf("*");
        printf("*");
}
else{
        printf("%04d\n", num);




}
return(0);
}//end bracket`
twin knollBOT
#
Program Output
" *****{Welcome to C291 Fall 2021 @ IU}, %%% Golden Rule: Start working on everything as early as possible %%% Thanks ***** 
"0100*****
prisma thistle
#

looks like it works to me

#

if that is what u want it to do

#

not sure why this whole thing is so weird but ye

sturdy brook
#

wait I just relized I forgot to do num--

prisma thistle
#

??

#

why is this fall 2021

sturdy brook
#

output should be:

0100*****
0099
0098*****
etc

#

Idk professor is using an old assignment

prisma thistle
#

ok so just dont make the loop infinite

#

;compile

twin knollBOT
#
Compiler Output
Killed - processing time exceeded
prisma thistle
#

tbh idk why it says that

sturdy brook
#

okay I got one step closer

prisma thistle
#

;compile

twin knollBOT
#
Compiler Output
Killed - processing time exceeded
prisma thistle
#

wtf

#
#include <stdio.h>
int main() {
  for (int i = 10; i >= 0; i--) {
    if (i % 2 == 0) printf("%d*", i);
    else printf("%d", i);
  }
  return 0;
}
twin knollBOT
#
Program Output
10*98*76*54*32*10*
prisma thistle
#

i dont understand why urs is infinite

#

after i edited the for loop

#

oh maybe its not infinite its just the sleeps

#

u made too many sleeps

hidden hatch
#

!f

forest fjordBOT
#

#include <stdio.h>
#include <unistd.h>

int main() {
  char welcome[] =
      "\" *****{Welcome to "
      "C291 Fall 2021 @ IU}"
      ", %%%%%% Golden Rule: S"
      "tart working on ever"
      "ything as early as p"
      "ossible %%%%%% Thanks *"
      "**** \n\"";

  printf(welcome);

  int num = 10;

  for (; num >= 0; num--) {
    /*      printf("I am a flag\n");
            printf("%04d\n", num);
            */
    if (num % 2 == 0) {
      printf("%04d", num);
      printf("*");
      sleep(1);
      printf("*");
      sleep(1);
      printf("*");
      sleep(1);
      printf("*");
      sleep(1);
      printf("*");
    } else {
      printf("%04d\n", num);
    }
  }
  return (0);
}  // end bracket`

EpistemologicalSoap
prisma thistle
#

for this discord bot to accept anyways

#

yeh i think its the sleeps

twin knollBOT
#
Program Output
" *****{Welcome to C291 Fall 2021 @ IU}, %%% Golden Rule: Start working on everything as early as possible %%% Thanks ***** 
"0100***
prisma thistle
#

oh wait that was the one where i removed the loop'

#

ok tjis is dum im done bye

forest fjordBOT
#

@sturdy brook Has your question been resolved? If so, run !solved :)

sturdy brook
#

thanks for the rubber ducky

#

!solved