1) do/while looks like this:
Code:
do {
/* Body */
} while ( condition );
No loop controls come after the while like in a normal while loop.
2) Each time you call getchar, you actually request input. Since you want a single character to test, only call getchar once.
3) Scanf will cause you problems when you mix it with getchar.
Here is something workable:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{ //begin of function main
int num; //number generated
int guess = 0;
int game = 0;
int counter = 0;
srand(time(NULL)); //generate the random seed generator
num = rand() % 100 +1 ; //pick a number from 1 to 100
printf("I will generate a random number between 1 and 100\n");
printf("Can you guess the number?\n");
printf("Please enter your first guess.\n");
do
{
while (num != guess)
{
scanf("%d", &guess);
++counter;
if (guess > 100 || guess <= 0)
{
printf("Number out of range\n");
printf("Try again\n");
}
else if (guess > num)
{
printf("Too High! try again!\n");
}
else if (guess < num)
{
printf("Too Low! try again!\n");
}
} //end while
printf("You guessed the number in %d tries!\n",counter);
//i = counter/ guess;
if(counter >= 16)
{
printf("You need more practice \n");
}
else if (counter >= 11 && counter <= 15)
{
printf("Your getting better \n");
}
else if (counter >= 6 && counter <= 10)
{
printf("Practice Pays off\n");
}
else if (counter >= 2 && counter <= 5)
{
printf("Nice job \n");
}
else if (counter == 1)
{
printf("You got lucky !!\n");
}
printf("Would you like to play again?\n");
printf("Enter n or N to quit\n");
while ( getchar() != '\n' )
;
game = getchar();
getchar();
} //end of do while
while (game != 'n' && game != 'N');
return 0;
}// end of main