- #include <iostream.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
-
- void main()
- {
-
- const int SIZE = 20;
- int nbCps = 0 , nbErr = 0 , fini = 0 , action = 0 , parti = 0 , tmp = 0;
- char phrase[20] , phrase2[20] , lettre;
-
- printf("**************************** Josue Clement\n");
- printf("********* LE PENDU ********* josue-clement@bluewin.ch\n");
- printf("**************************** le 20 mars 2002\n\n\n");
-
- printf("Entrez le mot a rechercher (max 20 car.): "); // Lecture de -
- gets(phrase); // la phrase
- system("cls"); // !!!!! pour borland : clrscr(); !!!!
-
- const int LNG = strlen(phrase); // Constante : longueur de la phrase
-
- for (int i = 0 ; i < LNG ; i++)
- {
- phrase2[i] = '-';
- }
-
- do
- {
- action = 0;
- tmp = 0;
- system("cls");
- printf("Nombre de coups : %i",nbCps);
- printf("\nNombre d'echecs: %i\n\n",nbErr);
- printf("Mot: ");
-
- for (int j = 0 ; j < LNG ; j++)
- {
- printf("%c",phrase2[j]);
- }
- printf("\n\nEntrez une lettre a rechercher: ");
- lettre = getche();
-
- for (int k = 0 ; k < LNG ; k++)
- {
- if (phrase2[k] == lettre)
- {
- action = 0;
- }
- if (phrase[k] == lettre && phrase2[k] != lettre)
- {
- phrase2[k] = lettre;
- action = 1;
- }
- }
- if (action == 0)
- {
- nbErr++;
- }
- nbCps++;
-
- for (int l = 0 ; l < LNG ; l++)
- {
- parti = 0;
- if (phrase[l] == phrase2[l])
- {
- tmp++;
- }
- }
- if (tmp == LNG)
- {
- parti = 1;
- }
-
- }while(nbErr != 9 && parti != 1);
-
- if (parti == 1)
- {
- system("cls");
- printf("Bravo, vour avez trouve \"%s\" en %i coups\n\n\n",phrase,nbCps);
- }
- if (nbErr == 9)
- {
- system("cls");
- printf("Vous avez perdu...\n");
- printf("Le mot etait: \"%s\"!\n\n\n",phrase);
- }
-
- system("pause");
-
- }
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
void main()
{
const int SIZE = 20;
int nbCps = 0 , nbErr = 0 , fini = 0 , action = 0 , parti = 0 , tmp = 0;
char phrase[20] , phrase2[20] , lettre;
printf("**************************** Josue Clement\n");
printf("********* LE PENDU ********* josue-clement@bluewin.ch\n");
printf("**************************** le 20 mars 2002\n\n\n");
printf("Entrez le mot a rechercher (max 20 car.): "); // Lecture de -
gets(phrase); // la phrase
system("cls"); // !!!!! pour borland : clrscr(); !!!!
const int LNG = strlen(phrase); // Constante : longueur de la phrase
for (int i = 0 ; i < LNG ; i++)
{
phrase2[i] = '-';
}
do
{
action = 0;
tmp = 0;
system("cls");
printf("Nombre de coups : %i",nbCps);
printf("\nNombre d'echecs: %i\n\n",nbErr);
printf("Mot: ");
for (int j = 0 ; j < LNG ; j++)
{
printf("%c",phrase2[j]);
}
printf("\n\nEntrez une lettre a rechercher: ");
lettre = getche();
for (int k = 0 ; k < LNG ; k++)
{
if (phrase2[k] == lettre)
{
action = 0;
}
if (phrase[k] == lettre && phrase2[k] != lettre)
{
phrase2[k] = lettre;
action = 1;
}
}
if (action == 0)
{
nbErr++;
}
nbCps++;
for (int l = 0 ; l < LNG ; l++)
{
parti = 0;
if (phrase[l] == phrase2[l])
{
tmp++;
}
}
if (tmp == LNG)
{
parti = 1;
}
}while(nbErr != 9 && parti != 1);
if (parti == 1)
{
system("cls");
printf("Bravo, vour avez trouve \"%s\" en %i coups\n\n\n",phrase,nbCps);
}
if (nbErr == 9)
{
system("cls");
printf("Vous avez perdu...\n");
printf("Le mot etait: \"%s\"!\n\n\n",phrase);
}
system("pause");
}