Guessing game that I got from a youtube video and wanted to ask a few questions that I didn't get. One what is the point of the else outofGuesses=1 part? Secondly when do you use one equal sign and when to use 2. Last but not least was there an easier way to do this like using a for statement?
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int secretNumber= 5;
int guess;
int guessCount=0;
int guessLimit=3;
int outofGuesses=0;
while(guess !=secretNumber && outofGuesses ==0)
{
if(guessCount< guessLimit)
{
printf("Enter a number between 1 and 10:");
scanf("%d", &guess);
guessCount++;
}
else
{
outofGuesses =1;
}
}
if(outofGuesses==1)
{
printf("You lost!");
}
else
{
printf("You win!");
return 0;
}
}
Aucun commentaire:
Enregistrer un commentaire