Created
April 23, 2020 19:57
-
-
Save Redeem-Grimm-Satoshi/bf7b1be68c1f1ac291f921bed38ce3a5 to your computer and use it in GitHub Desktop.
Play Guessing With Your Computer!
This file contains hidden or 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
/* | |
Author: Redeem Grimm. | |
Date: Can't Remember, But Wrote This Code Before The Pandermic. | |
Purpose: Play Guessing Game Against The Computer | |
*/ | |
#include<stdio.h> | |
#include<stdlib.h> | |
int main(){ | |
//random num generator | |
// srand(time(NULL)); | |
// secretNumber=rand()%10; | |
//variable declaration | |
int secretNumber; | |
//random number generator | |
srand ( time(NULL) ); | |
secretNumber = rand()%10; | |
//declaration continues | |
int guess; | |
int countAllGuess=0; | |
int countHighGuess=0; | |
int countLowGuess=0; | |
int totalGuess=0; | |
//loop will never end until guess==secretnumber | |
while(guess!=secretNumber){ | |
printf("Enter Guess: "); | |
scanf("%d",&guess); | |
if(guess>(secretNumber + 3)){ | |
printf("Guess too high, try a smaller number!\n"); | |
countHighGuess++; | |
}else if(guess<(secretNumber - 3)){ | |
printf("Guess too low, try a larger number!\n"); | |
countLowGuess++; | |
} | |
countAllGuess++; | |
} | |
//counting total guesses | |
totalGuess=(countAllGuess)-(countHighGuess+countLowGuess); | |
printf("You Won Using %d Guess(es), %d Guess(es) Were Too High And %d Guess(es) Were Too Low\n", totalGuess,countHighGuess,countLowGuess); | |
printf("A Total Of %d Guesses Were Made!\n",countAllGuess); | |
getch(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simplified As Usual!