fork(1) download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. ranguess();
  8.  
  9. Console.ReadLine(); // your code goes here
  10. }
  11. public static void ranguess()
  12. {
  13. int yn, rn;
  14. int c;
  15. Random rd = new Random(); //create random object
  16.  
  17. Console.Write("Enter your guess number:");
  18. yn = int.Parse(Console.ReadLine());
  19. rn =rd.Next(1,7);//generate random number from 1 t 6
  20. Console.WriteLine(rn);
  21. if (yn == rn)
  22. {
  23. Console.WriteLine("You won.");
  24.  
  25. }
  26. else
  27. {
  28. Console.WriteLine("You lost.");
  29. Console.WriteLine("My number is {0}.", rn);
  30. Console.WriteLine("Do you want to try again");
  31. Console.WriteLine("Press 1 to continue");
  32. c = int.Parse(Console.ReadLine());
  33. if (c == 1)
  34. {
  35. ranguess();
  36. }
  37. else
  38. {
  39. Console.WriteLine("Thank You");
  40. }
  41.  
  42.  
  43. }
  44. }
  45. }
  46.  
Success #stdin #stdout 0.04s 24248KB
stdin
5
1
1
2
stdout
Enter your guess number:3
You lost.
My number is 3.
Do you want to try again
Press 1 to continue
Enter your guess number:1
You won.