Skip to content

Instantly share code, notes, and snippets.

@Redeem-Grimm-Satoshi
Created April 23, 2020 19:57
Show Gist options
  • Save Redeem-Grimm-Satoshi/bf7b1be68c1f1ac291f921bed38ce3a5 to your computer and use it in GitHub Desktop.
Save Redeem-Grimm-Satoshi/bf7b1be68c1f1ac291f921bed38ce3a5 to your computer and use it in GitHub Desktop.
Play Guessing With Your Computer!
/*
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;
}
@Redeem-Grimm-Satoshi
Copy link
Author

Simplified As Usual!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment