Bonsoir à tous
Me revoila avec mon code (toujorus aussi titubant...) mais cette fois-ci, j'ai trouvé comment ne pas être bloqué par des char....
Seulement voila, je bloque à cause je pense de ma variable a qui prend toujorus la même valeur, et que je boucle tout le temps sans pouvoir saisir de nouvelle valeur de a
Pouvez vous me dire comment faire pour affecter une nouvelle valeur à a s'il vous plait ?
Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /*pour la fonction srand*/
int main ()
{
 
	int a, c;/*Declaration de deux variables, a pour l'humain et c pour l'ordinateur*/
	int j,m;/*Variable pour compter respectivement le gain du joueur ou de la machine*/
	int ok = 0;
	int retour;
	j=0;
	m=0;/*initialise à 0...*/
 
	while ((j|m)!=10){
 		printf("Choisir un chiffre, 0 pour papier, 1 pour pierre, 2 pour ciseau\n");/*L'humain choisi une valeur qui représente son choix*/
			a=NULL;
			while (!ok){				
				retour = scanf("%d%*[^\n]", &a);
 
				if ( !retour ){
				/* erreur de saisie, on vide le flux */
				int b;
				while ( ((b = getchar()) != '\n') && b != EOF);
				printf("on vous a demande de saisir un nombre\n");
				printf("veuillez recommencer :\n");
				}
 
				else {
				/* reussite de la saisie */
				getchar(); /* on enleve le '\n' restant */
				ok=1;
				}
			}
 
	srand(time(NULL));//Calcul d'un nombre aléatoire
	c=rand()%3;//et division par modulo pour limiter le nombre à 0, 1 ou 2
	if (a==c){
		printf("Personne n'a gagné\n");
		if (a==0){
		printf("L'ordinateur et vous avez choisi papier\n");
		}
		if (a==1){
		printf("L'ordinateur et vous avez choisi pierre\n");
		}
		if (a==2){
		printf("L'ordinateur et vous avez choisi ciseau\n");
		}
	}	
	else if ((a==0) && (c==1)) {
	printf("Vous avez gagné\n");
	j++;
	printf("L'ordinateur à choisi la pierre et vous le papier\n");
	}
	else if ((a==0) && (c==2)) {//code identique pour les differents cas...
	printf("Vous avez perdu\n");
	m++;
	printf("L'ordinateur à choisi les ciseaux et vous le papier\n");
	}
	else if ((a==1) && (c==0)) {
	printf("Vous avez perdu\n");
	m++;
	printf("L'ordinateur à choisi le papier et vous la pierre\n");
	}
	else if ((a==1) && (c==2)) {
	printf("Vous avez gagné\n");
	j++;
	printf("L'ordinateur à choisi les ciseaux et vous la pierre\n");
	}
	else if ((a==2) && (c==0)) {
	printf("Vous avez gagné\n");
	j++;
	printf("L'ordinateur à choisi le papier et vous les ciseaux\n");
	}
	else if ((a==2) && (c==1)) {
	printf("Vous avez perdu\n");
	m++;
	printf("L'ordinateur à choisi la pierre et vous les ciseaux\n");
	}
	else {//si le joueur n'a pas choisi un nombre 0, 1 ou 2, affiche un message d'erreur
	printf("Veuillez entrer un nombre compris entre 0 et 2\n");
	}	
	}
	if (j>m){
	printf("Bravo, vous avez gagné la partie !\n");
	}
	else{
	printf("Désolé, vous avez perdu la partie !\n");
	}
	return 0;
}