Well I am stumped. Must be scanf but tried fgets and no dice.
See what you can do with this.
The program runs nicely through until ready to do it again and then the program loops forever.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int
main(void){
int decision = 121, guessedNum;
while(decision == 121){
srand( time(NULL));
int target = rand() % 100 + 1, count = 0;
while (guessedNum != target){
printf("Guess a number between 1 and 100: ");
scanf("%d", &guessedNum);
fflush(stdin);
if (guessedNum > target){
printf("The number is lower. Try again.\n");
count += 1;
}
else if(guessedNum < target){
printf("The number is higher. Try again.\n");
count += 1;
}
else
{
printf("You guessed correctly!\n");
printf("It took you %d tries.\n", count);
}
}
printf("Would you like to play again? y(es) or n(o) :");
scanf("%d", &decision);
}
return 0;
}