rand-time

title: "courses/c-course - rand-time.md"

- **fileName**: rand-time
- **Created on**: 2024-06-08 14:56:51

for random number using the library

#include <stdlib.h> -> for rand and srand
#include <time.h> -> for using the time in srand

 srand(time(0)); // for every time using the current time to get random number
(rand() % 10) + 1; // getting the random number between 0 and 10

game for guessing random number

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

int main() {

  srand(time(0));
  int guesses;
  int guess;
  int random_score;
  random_score = (rand() % 10) + 1;

  do {
    printf("\n pls enter guess number: ");
    scanf("%d", &guess);
    if ( guess > random_score) printf(" \n score is too hight: %d", guess);
    else if ( guess < random_score) printf("\n score is too low: %d", guess);
    else 
      printf("\n---------------------");
      printf("\nsuccess guessingi: %d", guess);
      printf("\n---------------------"); 
  }while (guess != random_score);

  return 0;
};

continue:[[]]
before:struct-typedef-enum.md