Guest User

Jeux du nombre

a guest
Sep 30th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3.  
  4.  
  5. namespace WindowsFormsApp1
  6. {
  7.    
  8.     static class Program
  9.     {
  10.        
  11.  
  12.         static void Main()
  13.         {
  14.             //utilisation d'une boucle do while au lieu de while afin de mettre à jour la variable msgOK
  15.  
  16.             String reponse, fin ;
  17.             Boolean msgOK;
  18.             DialogResult test;
  19.          String msg;
  20.             int msgINT;
  21.             int incre = 0;
  22.  
  23.          
  24.  
  25.             Random aleatoire = new Random();
  26.                 int chiffre1 = aleatoire.Next(1, 100);
  27.  
  28.             do
  29.             {
  30.                 msg = Jim.InputBox("Input", "Pick a number between 1 and 100", "50");
  31.                 msgINT = int.Parse(msg);
  32.  
  33.                 if (msgINT < chiffre1)
  34.             {
  35.                 reponse = "It's more !";
  36.                     msgOK = false;
  37.                     incre++;
  38.             }
  39.  
  40.             else if (msgINT > chiffre1)
  41.             {
  42.                 reponse = "It's less !";
  43.                 msgOK = false;
  44.                     incre++;
  45.                    
  46.             }
  47.             else
  48.             {
  49.                 reponse = "Hurray, you've got the right number !";
  50.                 msgOK = true;
  51.                     incre++;
  52.             }
  53.                 fin = "\t" + msgOK + ", " + reponse + "\n\t" + "Counting your tries : " + incre ;
  54.                 test = MessageBox.Show(fin, "Input", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  55.              
  56.  
  57.             } while(msgOK == false);
  58.            
  59.            
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment