Created
March 16, 2021 23:41
-
-
Save codingminecraft/50599773da541765687f185a73a6b438 to your computer and use it in GitHub Desktop.
GuessNumber.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
IF NOT EXIST bin mkdir bin | |
IF NOT EXIST bin-int mkdir bin-int | |
pushd bin-int | |
cl ..\guessNumber.cpp /link | |
popd | |
move bin-int\guessNumber.exe bin\guessNumber.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <time.h> | |
int main() | |
{ | |
const int maxNumber = 100; | |
const int minNumber = 0; | |
srand(time(NULL)); | |
int generatedNumber = (rand() % (maxNumber - minNumber + 1)) + minNumber; | |
printf(">> I'm thinking of a number between %d and %d.\n", minNumber, maxNumber); | |
int userGuess; | |
do | |
{ | |
printf(">> Make a guess: "); | |
scanf("%d", &userGuess); | |
printf("\n\n"); | |
if (userGuess < generatedNumber) | |
{ | |
printf(">> Guess higher.\n"); | |
} | |
else if (userGuess > generatedNumber) | |
{ | |
printf(">> Guess Lower.\n"); | |
} | |
else | |
{ | |
printf(">> You Got it!\n"); | |
printf(">> Play again? (y/n) "); | |
char playAgain; | |
scanf(" %c", &playAgain); | |
if (playAgain == 'y' || playAgain == 'Y') | |
{ | |
generatedNumber = (rand() % (maxNumber - minNumber + 1)) + minNumber; | |
printf(">> I'm thinking of a number between %d and %d.\n", minNumber, maxNumber); | |
} | |
} | |
} while (userGuess != generatedNumber); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment