I am new to C and having some issues with a program. The program should note guesses outside the legal range shall (1-100) be noted to the user and counted as guesses.
I am also having issues with the continuation of the program until a key word is entered.
I am only looking for suggestions
Thank you for any help.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int num;
int guess =0;
int counter =0;
int total;
int i;
total = counter;
srand(time(NULL)); //generate the random seed generator
num = rand() % 100 +1 ; //pick a number from 1 to 100
printf("I generate a random number between 1 and 100\n");
printf("Can you guess the number?\n");
printf("Please enter your first guess.\n");
scanf("%d", &guess);
while (num != guess)
{
if (guess > 100 && guess < 0)
{
printf("Number out of range\n");
printf("Try again\n");
++counter;
}
else if (guess > num)
{
printf("Too High! try again!\n");
scanf("%d", &guess);
++counter;
}
else if (guess < num)
{
printf("Too Low! try again!\n");
scanf("%d", &guess);
++counter;
}
} //end while
printf("You guessed the number in %d tries!\n",counter);
i = counter/ guess;
if(counter >= 16)
{
printf("You need more practice \n",counter);
}
else if (counter >= 11 && counter <= 15)
{
printf("Your getting better \n",counter);
}
else if (counter >= 6 && counter <= 10)
{
printf("Practice Pays off\n");
}
else if (counter >= 2 && counter <= 5)
{
printf("Nice job \n",counter);
}
else if (counter == 1)
{
printf("You got lucky !!\n",counter);
}
printf("%d is the average number of tries\n",i);
return 0;
}//end of main
[COLOR=darkblue]