Hello fellow coders! I am kind of stuck on one aspect of a project that I am currently working on. I have a code for a number guessing game in "C" but I need some assistance as to how to add a "high score" feature to the game. Basically, I want the lowest score to be the best, the score being how many guesses it took the user to get the correct answer. Any help at all will be greatly appreciated! Here is the code thus far:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
int main( void )
{
srand(time(NULL));
int i,n=0,r=rand()%100 + 1;
(void)printf("Welcome to GUESSTIMATOR 2000\n\nI am thinking of a number between 1 and 100. \n\nCan you guess what it is? ");
while(scanf("%d",&i))
{
if (n >= 9 && i != r)
{
printf("\n\nSorry, the number was %d.\n", r);
printf("You should have gotten it by now.\n");
printf("Better luck next time.\n\n");
system ("PAUSE");
break; }
if (i > r)
{
n++;
printf("Your guess is high. You only get 10 guesses. Try again: ");
}
else if (i < r)
{
n++;
printf("Your guess is low. You only get 10 guesses. Try again: ");
}
else if (i == r)
{
printf("\n\nCongratulations!\nYou guessed the number within %d guesses! \n\n", n+1);
system ("PAUSE");
return;
}
}
return 0;
}