Unnecessary hard game – Guess the number in C

So this is a nice C game that you have to guess a number but….. it is hard for no reason. You can make it even harder by amending 1000 to a higher number equally you can make it easier by lowering it.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void) {
    srand(time(NULL));
    int r = rand() % 1000 + 1;
    int complete = 0; 
    int try; 
    int countdown = 1; 
 

    printf("Lets play a game - I have generated a number and all you have to do is guess it! X-D\n "); 

    do {
        scanf("%d", &try);
        if (try == r) {
            countdown++;
            printf("How did you get that and in %d tries! I'm impressed\n", countdown);
            complete = 1; 
        }

        if (try < r) {
            countdown++;
            printf("Nope you are too low, Try again lol.\n You are currently on Guess no: %d\n Enter your guess: ", countdown);
        }

        if (try > r) { 
            countdown++; 
            printf("Nope that number is too high, Try again lol.\n You are currently on Guess no: %d\n Enter your guess: ", countdown);
        }
    } while (complete == 0);

    return 0;
}

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *