Week 2 Code Examples

#include <stdio.h>

int main(void) {
    int answer = 94;
    int guess = -1;

    while (guess != answer) {
        printf("Guess how many free energy drinks were given out at O-week to win a prize: ");
        scanf("%d", &guess);
        
        if (guess == answer) {
            printf("Congratulations!\n");
            printf("Goodbye!\n");
        } else if (answer - guess <= 5 && answer - guess >= -5) {
            printf("So close! But no cigar, because smoking is bad!\n");
        } else if (guess < answer) {
            printf("Lmao too small\n");
        } else {
            printf("That guess is too big, get rekt\n");
        }
    }
}
#include <stdio.h>

int main(void) {
    int order = 66;
    if (!(order > 60 && (order % 2 == 1 || order < 70))) {
        printf("The Jedi are safe\n");
    }
    return 0;
}
#include <stdio.h>

int main(void) {
    int number;
    printf("What is your favourite number: ");
    scanf("%d", &number);
    if (number == 15) {
        printf("That's Henry's birthday!\n");
    } else if (number == 12) {
        printf("That's pretty neat\n");
    } else if (number == 10) {
        printf("That's actually 2 in binary\n");
    } else {
        printf("I'm not smart enough to come up with anything clever here\n");
    }
    return 0;
}
#include <stdio.h>

int main(void) {
    int season = 7;
    if (season > 8) {
        printf("That's a new season\n");
    } if (season % 2 == 1) {
        printf("That's a pretty odd season\n");
    } if (season == 8) {
        printf("George was robbed\n");
    } else {
        printf("That's a lot of statements\n");
    }
}
#include <stdio.h>

int main(void) {
    printf("%lf", 29/10.0);
}