Navigation Menu

Skip to content
This repository has been archived by the owner on Oct 23, 2018. It is now read-only.

Commit

Permalink
Add Vala sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Skao93 committed Oct 11, 2018
1 parent eda5b72 commit c8af9d1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Vala/count.vala
@@ -0,0 +1,35 @@

void start (int min, int max) {
int try_count = 0;
int number = Random.int_range (min, max);

stdout.printf ("Bienvenido a Adivina el número\n\n");
stdout.printf ("Tengo pensado un número entre %d y %d, ", min, max);
stdout.printf ("el cual tienes que adivinar. Pero tranquilo, te voy");
stdout.printf ("a dar algunas pistas\n\n");

while (true) {
try_count++;

stdout.printf ("Intento #%d\n", try_count);
stdout.printf ("Por favor ingrese un número entre %d y %d: ", min, max);
int input = int.parse (stdin.read_line ());

if (number == input) {
stdout.printf ("¡Ganador! Lo hiciste en %d intentos\n", try_count);
break;
} else {
stdout.printf ("Error, el número es %s que %d.\n",
number > input ? "mayor" : "menor", input);
}
}
}
static int main (string[] args){
stdout.printf("Ingrese el mínimo: ");
int min = int.parse(stdin.read_line());
stdout.printf("Ingrese el máximo: ");
int max = int.parse(stdin.read_line());
start(min, max);
return 0;

}

0 comments on commit c8af9d1

Please sign in to comment.