Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RandomNumber2.aspx.cs" Inherits="RandomNumber2" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <script runat = "server">
- int num1 = 1, num2 = 1, num3 = 1;
- Random rnd= new Random();
- public void GetRand(int n)
- {
- num1 = rnd.Next(1, n + 1);
- num2 = rnd.Next(1, n + 1);
- num3 = rnd.Next(1, n + 1);
- }
- public int CalcPoints(string name,int n)
- {
- int points = 0;
- GetRand(n);
- if (num1 == num2 && num2 == num3)
- points += 10;
- else if (num1 == num2 && num2 != num3 || num2 == num3 && num2 != num1)
- points += 5;
- if (isValidName(name))
- points += 2;
- else
- points -= 2;
- return points;
- }
- public bool isValidName(string name)
- {
- return (name != null && name != "");
- }
- </script>
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <%
- if (Page.IsPostBack)
- {
- int n = int.Parse(Request.Params["number"]);
- string name = Request.Params["fname"];
- int points = CalcPoints(name, n);
- %>
- Hello <%=name%> You have chosen number <%=n%>
- The random numbers are : <%=num1 + " , " + num2 + " , " + num3%>
- You have scored <%=points%> points!
- <%
- }
- %>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement