#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int stime;
long ltime;
int thisRandomNumbe r;
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 */
thisRandomNumbe r= rand() %100 + 1;
userTries=0;
do{
printf("Guess the random computer generated number:\n");
scanf("%d",&use rinput);
if (userinput == thisRandomNumbe r){
printf("That's the number!\n");
}
else if (userinput > thisRandomNumbe r){
printf("Your guess is higher than the number.\n");
}
else if(userinput < thisRandomNumbe r){
printf("Your guess is lower than the number.\n");
userTries++;
}
while (thisRandomNumb er!=userinput);
printf("\nCongr atulations! That is the number! It took you %d tries", userTries);
return 0;
}
#include <stdlib.h>
#include <time.h>
int main(void)
{
int stime;
long ltime;
int thisRandomNumbe r;
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 */
thisRandomNumbe r= rand() %100 + 1;
userTries=0;
do{
printf("Guess the random computer generated number:\n");
scanf("%d",&use rinput);
if (userinput == thisRandomNumbe r){
printf("That's the number!\n");
}
else if (userinput > thisRandomNumbe r){
printf("Your guess is higher than the number.\n");
}
else if(userinput < thisRandomNumbe r){
printf("Your guess is lower than the number.\n");
userTries++;
}
while (thisRandomNumb er!=userinput);
printf("\nCongr atulations! That is the number! It took you %d tries", userTries);
return 0;
}
Comment