i want to build a program that generate a random number then the user try to guess the number and if he filed to find it or if he find it the program ask the user if he will play again and if he play again the number change i did every thing right but i cant make the program change every time ! and this my code .>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int ra();
int main() {
int count , guess , r = 1+(rand()%10);
int play = 1;
int changeN;
while(play == 1){
changeN = ra();
printf("Guess the number \n");
scanf(" %d", &guess);
for (count = 0; count <= 3; count++) {
if(guess == r) {
printf("Well done\n");
break;
}
if (guess > r){
printf("wrong try smaller\n");
scanf(" %d", &guess);
count++ ;
}
else {
printf("wrong try biger\n");
scanf(" %d", &guess);
count++ ;
}
}
if (count == 4 ){
printf("you lost \n");
}
printf("Would you like to play again?\n 1 for yes 2 to end ");
scanf("%d",&play);
}
return 0;
}
int ra(){
srand(time(NULL));
return 0+rand()%(10-0+1);
}
Aucun commentaire:
Enregistrer un commentaire