Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2012
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RandomNumber2.aspx.cs" Inherits="RandomNumber2" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <script runat = "server">
  5. int num1 = 1, num2 = 1, num3 = 1;
  6. Random rnd= new Random();
  7. public void GetRand(int n)
  8. {
  9. num1 = rnd.Next(1, n + 1);
  10. num2 = rnd.Next(1, n + 1);
  11. num3 = rnd.Next(1, n + 1);
  12. }
  13. public int CalcPoints(string name,int n)
  14. {
  15. int points = 0;
  16. GetRand(n);
  17. if (num1 == num2 && num2 == num3)
  18. points += 10;
  19. else if (num1 == num2 && num2 != num3 || num2 == num3 && num2 != num1)
  20. points += 5;
  21. if (isValidName(name))
  22. points += 2;
  23. else
  24. points -= 2;
  25. return points;
  26. }
  27. public bool isValidName(string name)
  28. {
  29. return (name != null && name != "");
  30. }
  31. </script>
  32. <html xmlns="http://www.w3.org/1999/xhtml">
  33. <head runat="server">
  34. <title>Untitled Page</title>
  35. </head>
  36. <body>
  37. <%
  38. if (Page.IsPostBack)
  39. {
  40. int n = int.Parse(Request.Params["number"]);
  41. string name = Request.Params["fname"];
  42. int points = CalcPoints(name, n);
  43. %>
  44. Hello <%=name%> You have chosen number <%=n%>
  45. The random numbers are : <%=num1 + " , " + num2 + " , " + num3%>
  46. You have scored <%=points%> points!
  47. <%
  48. }
  49. %>
  50. </body>
  51. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement