I wanted to make a game where in which you get three turns to guess the selected number, from the computer. However it will never say well done even if you get the number right (already tested using printf statements) and the loop will also mess up by either continuing or running twice.
I've tried removing the break. I've put in printf statements to check if randomise and questions actually store the correct values and they do.
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <time.h>
int questions(){
int num;
printf("Chose a number between one - ten: ");
scanf("%d",&num);
return num;
}
int randomise() {
int roll;
srand(time(NULL));
roll = rand()%10 + 1;
return roll;
}
int main(){
int chosenNum, enteredNum, i;
chosenNum = randomise();
enteredNum = questions();
for(i = 0; i < 10; i++){
if(chosenNum != enteredNum){
questions();
break;
}
else if(chosenNum == enteredNum){
printf("WELL DONE !!!");
}
}
return 0;
}
Zero errors and Zero warnings. and the outcome should be that you get greeted with well done.
Aucun commentaire:
Enregistrer un commentaire