Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------------
- -- * devinette.adb
- -- * Role : deviner le nombre pensé par un utilisateur
- ----------------------------------------------------------------
- with entrees_sorties; use entrees_sorties;
- procedure devinette is
- nbMin, nbMax, nbMoy : Integer;
- indice : Integer;
- nbTrouve : Integer;
- nbCoups : Integer;
- begin
- nbCoups := 0;
- nbTrouve := 0;
- nbMin := 1;
- nbMax := 100;
- nbMoy := 0;
- put("Pensez a un entier entre 1 et 100");
- new_line;
- while(nbTrouve = 0) loop
- nbMoy := nbMin + (nbMax - nbMin)/2;
- put("Tapez -1 si votre nombre est inferieur a ");
- put(nbMoy, 0);
- put(", 1 s'il est superieur, 0 si egal.");
- new_line;
- get(indice);
- new_line;
- if(indice = 0) then
- nbTrouve := nbMoy;
- else
- if(indice < 0) then
- nbMax := nbMoy-1;
- else -- indice > 0
- nbMin := nbMoy+1;
- end if;
- end if;
- nbCoups := nbCoups + 1;
- end loop;
- put("J'ai trouve en ");
- put(nbCoups, 0);
- if(nbCoups > 1) then
- put(" coups !");
- else
- put("coup !");
- end if;
- end devinette;
Advertisement
Add Comment
Please, Sign In to add comment