samedi 28 mars 2020

rand() always gives the same number [duplicate]

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



int main(void){
  int i,res;
  scanf("%d",&i);
  res = rand() % 36;
  printf("%d\n",res);
  if(i == 'O' && res % 2 == 1){//odd-win
    printf("WIN 2x\n");

  } 
  else if(i == 'E' && res % 2 == 0 && res != 0){ // even-win
    printf("WIN 2x\n");

  }
  else if(i == res){
    printf("WIN 35x\n");
  }
  else{
    printf("LOSE!\n");
  }


  return 0;
}

Well, I just made a simple roulette game but whenever I scan user's input, rand function always gives the same number 19. How can I fix this ?




Aucun commentaire:

Enregistrer un commentaire