C - Programming Language
This course covers the basics of programming in C. Work your way through the videos/articles and I'll teach you everything you need to know to start your programming journey!

Building A Guessing Game

Lesson 23
Author : Mike Dane
Last Updated : November, 2017


Code

Copyint secretNum = 7;
int guess;
int guessCount = 0;
int guessLimit = 3;
int outOfGuesses = 0;

while(guess != secretNum && outOfGuesses == 0){
     if(guessCount < guessLimit){
          printf("Enter a guess: ";
          scanf("d", &guess);
          guessCount++;
     } else {
          outOfGuesses = 1;
     }
}

if(outOfGuesses != 0){
     printf("You Lose!");
} else {
     printf("You Win!");
}