I wasn't too clear on do while loops before doing this, but I think I have a lot more of an understanding now. However, I keep on getting an error when I try to compile it...
guessinggame.c: In function âmainâ:
guessinggame.c:51: error: expected âwhileâ at end of input
guessinggame.c:51: error: expected declaration or statement at end of input
and here's my source code again:
Code:
/*
@author:
@date/version:20102405.01
@title:Guessing Game
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int stime;
long ltime;
int thisRandomNumber;
int userinput;
int userTries;
/* get the current time and then send the random number */
ltime= time(NULL);
stime= (unsigned) ltime/2;
srand(stime);
//calculate a random number between 1 and 100 */
thisRandomNumber= rand() %100 + 1;
userTries=0;
do{
printf("Guess the random computer generated number:\n");
scanf("%d",&userinput);
if (userinput == thisRandomNumber){
printf("That's the number!\n");
}
else if (userinput > thisRandomNumber){
printf("Your guess is higher than the number.\n");
}
else if(userinput < thisRandomNumber){
printf("Your guess is lower than the number.\n");
userTries++;
}while (thisRandomNumber!=userinput);
printf("\nCongratulations! That is the number! It took you %d tries", userTries);
return 0;
}