Created
March 31, 2020 13:13
-
-
Save wRadion/956505de8b2c9aacbefe8c577c847ea7 to your computer and use it in GitHub Desktop.
Cours Jour 2 - Guess The Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace CoursJour2 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
while (true) | |
{ | |
int randomNumber = GenerateRandomNumber(0, 100); | |
while (true) | |
{ | |
int userGuess = AskNumberToUser(); | |
// si le nombre est égal au nombre aléatoire | |
if (userGuess == randomNumber) | |
{ | |
// il a gagné | |
Console.WriteLine("Bravo ! Tu as gagné !"); | |
break; | |
} | |
else if (userGuess > randomNumber) | |
{ | |
Console.WriteLine("Trop grand !"); | |
} | |
else // if (userGuess < randomNumber) | |
{ | |
Console.WriteLine("Trop petit !"); | |
} | |
} | |
// demande si il veut rejouer | |
Console.Write("Est-ce que tu veux rejouer ? "); | |
string answer = Console.ReadLine(); | |
// si il tape "oui" | |
if (answer != "oui") | |
{ | |
break; | |
} | |
} | |
Console.ReadKey(); | |
} | |
static int GenerateRandomNumber(int min, int max) | |
{ | |
return new Random().Next(min, max); | |
} | |
static int AskNumberToUser() | |
{ | |
Console.Write("Entrez un nombre entre 0 et 100 : "); | |
string userInput = Console.ReadLine(); | |
return int.Parse(userInput); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment