Skip to content

Instantly share code, notes, and snippets.

@xanecs
Created February 20, 2016 15:36
Show Gist options
  • Save xanecs/b20f9f32dd2cd3028aba to your computer and use it in GitHub Desktop.
Save xanecs/b20f9f32dd2cd3028aba to your computer and use it in GitHub Desktop.
C Number guessing game
#include <stdio.h>
#include <stdlib.h>
int main () {
srand(time(NULL));
int randNum = rand() % 9999;
while (1) {
printf("Guess a number: ");
int guessNum;
scanf("%d", &guessNum);
if (guessNum == randNum) {
printf("You are correct! Buy yourself a cookie!\n");
break;
}
if (guessNum < randNum) {
printf("Your guess is too small!\n");
}
else if (guessNum > randNum) {
printf("Your guess is too damn high!\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment