Update to Unnecessary hard game

I have made some slight modifications to Unnecessary hard game. The changes are:

  • Reworded some print statments
  • Changed the colouring of the text depending on the answer you gave
  • Put in a goto statement so the game will restart upon correct guess
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>


#define FONTGREEN "\x1b[32m"
#define FONTRESET "\x1b[0m"
#define FONTRED "\x1b[31m"



int main(void) {
    
    start:
    
    
    srand(time(NULL));
    int r = rand() % 1000 + 1;
    int complete = 0; 
    int try; 
    int countdown = 0; 
    
    
system ("clear");
    printf("Lets play a game - I have generated a number and all you have to do is guess it!: "); 

    do {
        scanf("%d", &try);
        if (try == r) {
            countdown++;
            printf(FONTGREEN "How did you get that and in %d tries! I'm impressed\n", countdown);
           
            printf("LETS START AGAIN.\n\n*****Are you ready*****\nyour next game starts in 10 seconds\n" FONTRESET );
             
            sleep (10);
           
            complete = 1; 
            
        }

        if (try < r) {
            countdown++;
            printf(FONTRED "Try number %d, too low,\nPlease try again: " FONTRESET, countdown);
        }

        if (try > r) { 
            countdown++; 
            printf(FONTRED "Try number %d was too high\nplease try again: " FONTRESET, countdown);
        }
        
        
        
        
    } while (complete == 0);
    
  

    goto start;
    
    return 0;
}

Related Post

2 thoughts on “Update to Unnecessary hard game

Leave a Reply

Your email address will not be published.