Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Bhasvic Computer Science Chapter 1 - 7b

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    srand(time(NULL));
    
    int randNum = rand()%100,userNum=0,correct=0;
    
    while(correct==0)
    {
        printf("Guess the hidden number between 0 and 99:");
        scanf("%d",&userNum);
    
        if(userNum==randNum)
        {
            printf("Congratulations! You guessed correctly!");
            correct=1;
        }
        else if(userNum<randNum)
        {
            printf("You guessed too low\n");
            printf("Better luck next time\n");
        }
        else
        {
            printf("You guessed too high\n");
            printf("Better luck next time\n");
        }
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.