i did not run this program.then i want to know where are eror this code.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deep420
    New Member
    • Jun 2014
    • 1

    i did not run this program.then i want to know where are eror this code.

    #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;
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You have two basic errors.

    Code:
    ltime= time(NULL);
    ltime is a long whereas the time function returns a time_t.
    The ltime needs to be a time_t.

    The second error is your do-while loop. There is no while part.

    Comment

    Working...