Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET C#个性测试_C#_Asp.net - Fatal编程技术网

ASP.NET C#个性测试

ASP.NET C#个性测试,c#,asp.net,C#,Asp.net,我认为我在ASP.NET中使用C#编写的人格测试代码很好。但有时有效,有时无效。我没有发现任何语法错误,就像我说的,有时候它工作得很完美。有没有我遗漏的逻辑错误 <%@ Page Language="C#" Debug="true" %> <!DOCTYPE html> <script runat="server"> public int m_score = 0; public int m_imageScore = 0; //Displaying t

我认为我在ASP.NET中使用C#编写的人格测试代码很好。但有时有效,有时无效。我没有发现任何语法错误,就像我说的,有时候它工作得很完美。有没有我遗漏的逻辑错误

<%@ Page Language="C#" Debug="true" %>

<!DOCTYPE html>
<script runat="server"> 

public int m_score = 0;
public int m_imageScore = 0;


//Displaying the autopostback message for the selection of the workList drop-down list
protected void workListChanged(object sender, EventArgs e)  
{
    if (workList.SelectedItem.Text == "Office Work")
        lblWork.Text = "You prefer to stay inside and code your life away.";
    else if (workList.SelectedItem.Text == "Outdoor Work")
        lblWork.Text = "You enjoy the great outdoors.";
    else if (workList.SelectedItem.Text == "Investigative Work")
        lblWork.Text = "OK, Sherlock.";
    else if (workList.SelectedItem.Text == "Working With People")
        lblWork.Text = "As opposed to extraterrestirals?";
    else if (workList.SelectedItem.Text == "Work Requiring Travel")
        lblWork.Text = "I can show you the world . . . ";
    else if (workList.SelectedItem.Text == "Helping People")
        lblWork.Text = "You're a noble spirit.";
}  


//Finding the score for the which part of the image the user clicked
 public void ImageButton_Click(object sender, ImageClickEventArgs e)
{

    if ((e.X > 2 && e.X < 87) && (e.Y > 2 && e.Y < 120))
        m_imageScore = 50;
    else if ((e.X > 96 && e.X < 212) && (e.Y > 1 && e.Y < 89))
        m_imageScore = 25;
    else if ((e.X > 2 && e.X < 87) && (e.Y > 121 && e.Y < 211))
        m_imageScore = 10;
    else if ((e.X > 124 && e.X < 212) && (e.Y > 94 && e.Y < 218))
        m_imageScore = 5;

}

//Finding score for Checkbox List
 public void CheckBoxList(object sender, EventArgs e)
 {
     foreach (ListItem item in CheckBoxlist1.Items)
         if (item.Selected)
         {
             m_score = Int32.Parse(item.Value) + m_score;
         }
 }

 //Finding score for the remaining lists
 public void ButtonClick1(object sender, EventArgs e)
 {
    m_score = textComments.Text.Length + m_score;
    m_score = Int32.Parse(DropDownList1.SelectedItem.Value) + m_score;
    m_score = Int32.Parse(RadioButtonList1.SelectedItem.Value) + m_score;
    m_score = Int32.Parse(workList.SelectedItem.Value) + m_score;

    int final_score = m_score + m_imageScore;
    if (final_score > 100)
        lblresults.Text = "You are an outgoing personality type.";
    else if (final_score > 100 && final_score <50)
        lblresults.Text = "You are a merry soul.";
    else if (final_score < 50 && final_score > 25)
        lblresults.Text = "You are a regular kind of all-around person.";
    else if (final_score <25 && final_score > 0)
        lblresults.Text = "You are a shy one, aren't you?";

 }








</script>

<html>
<head id="Head1" runat="server">
<title>Personality Test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
    <asp:Label id="lblName"
        Text="Name"
        AssociatedControlID="txtName"
        runat="server" />

    <asp:TextBox
        id="txtname"
        AutoPostBack="true"
        runat="server" />

    <br /><br />

    <asp:TextBox
        id="textComments"
        Text="Tell me a little about yourself"
        TextMode="MultiLine"
        Columns="30"
        rows="10"
        runat="server" />
    <br /><br />

    <strong>Select a gender:</strong>
    <asp:RadioButton
        id="rd1Male"
        Text="Male"
        GroupName="rgGender"
        runat="server" />

    <asp:RadioButton
        id="rd1Female"
        Text="Female"
        GroupName="rgGender"
        runat="server" />
    <br /><br />


    <strong>Favorite Season:</strong>
    <br />
     <asp:DropDownList
         id="DropDownList1"
         Runat="server"
         AutoPostBack="true"
         >
    <asp:ListItem value="15">Spring</asp:ListItem>
    <asp:ListItem value="10">Summer</asp:ListItem>
    <asp:ListItem value="20">Fall</asp:ListItem>
    <asp:ListItem value="5">Winter</asp:ListItem>
    </asp:DropDownList>
    <br /><br />


    <strong>Which of the following colors are your favorite?</strong>
    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem Value="3">Red</asp:ListItem>
        <asp:ListItem Value="4">Blue</asp:ListItem>
        <asp:ListItem Value="7">Purple</asp:ListItem>
        <asp:ListItem Value="5">Yellow</asp:ListItem>
        <asp:ListItem Value="6">Green</asp:ListItem>
        <asp:ListItem Value="2">Orange</asp:ListItem>
        <asp:ListItem Value="8">Violet</asp:ListItem>
        <asp:ListItem Value="9">Pink</asp:ListItem>
        <asp:ListItem Value="10">Brown</asp:ListItem>
        <asp:ListItem Value="0">Grey</asp:ListItem>
    </asp:RadioButtonList>

    <br /><br />
    <strong>Which type of work do you prefer?</strong>
    <br />
      <asp:DropDownList
         id="workList"
         Runat="server"
         AutoPostBack="true"
         OnSelectedIndexChanged="workListChanged">
    <asp:ListItem Value="3">Office Work</asp:ListItem>
    <asp:ListItem value="2">Outdoor Work</asp:ListItem>
    <asp:ListItem value="7">Investigative Work</asp:ListItem>
    <asp:ListItem value="6">Woring With People</asp:ListItem>
    <asp:ListItem value="5">Work Requiring Travel</asp:ListItem>
    <asp:ListItem value="4">Helping Others</asp:ListItem>
    </asp:DropDownList>
    <br />

    <asp:Label
        id="lblWork"
        runat ="server" />
    <br /><br />


    <strong>Which foods do you like (check as many as you want)</strong>
    <asp:CheckBoxList 
    id="CheckBoxlist1" 
    runat="server" 
    RepeatColumns="6"
     RepeatDirection="Horizontal"
     TextAlign="Right">
    <asp:ListItem value="13">Bread</asp:ListItem>
    <asp:ListItem value="14">Carrots</asp:ListItem>
    <asp:ListItem value="1">Ice Cream</asp:ListItem>
    <asp:ListItem value="2">Potato Chips</asp:ListItem>
    <asp:ListItem value="5">Candy Bars</asp:ListItem>
    <asp:ListItem value="7">Cheesecake</asp:ListItem>
    <asp:ListItem value="16">Steak</asp:ListItem>
    <asp:ListItem value="9">Soft Drinks</asp:ListItem>
    <asp:ListItem value="15">Milk</asp:ListItem>
    <asp:ListItem value="11">Spaghetti</asp:ListItem>
    <asp:ListItem value="11">Pizza</asp:ListItem>
    <asp:ListItem value="17">Cheese</asp:ListItem>
    <asp:ListItem value="15">Almonds</asp:ListItem>
    <asp:ListItem value="3">Brownies</asp:ListItem>
    <asp:ListItem value="13">Apples</asp:ListItem>
    <asp:ListItem value="14">Oranges</asp:ListItem>
    <asp:ListItem value="15">Melons</asp:ListItem>
    <asp:ListItem value="14">Peas</asp:ListItem>
    <asp:ListItem value="19">Brussel Sprouts</asp:ListItem>
    <asp:ListItem value="15">Salads</asp:ListItem>
    <asp:ListItem value="14">Tuna Fish</asp:ListItem>
    </asp:CheckBoxList>
    <br /><br />
    <strong>Which picture most appeals to you?</strong>
    <br />
    <asp:ImageButton
        id="imgChoice"
        imageURL="PersTest.jpg"
        runat="server"
        OnClick="ImageButton_Click" />
    <br /><br /><br /><br />

    <asp:Button
        id="btnPersonality"
        Text="Submit Personality"
        runat="server" 
        OnClick="ButtonClick1"/>
    <br /><br />

    <asp:Label
        id="lblresults"
        runat="server" />



</div>
</form>
</body>
</html>

公共int m_分数=0;
公共int m_imageScore=0;
//显示用于选择工作列表下拉列表的自动回发消息
受保护的无效工作列表已更改(对象发送方、事件参数e)
{
如果(workList.SelectedItem.Text==“办公室工作”)
lblWork.Text=“你更喜欢呆在家里,把你的生活编码掉。”;
else if(workList.SelectedItem.Text==“户外工作”)
lblWork.Text=“你喜欢户外活动。”;
else if(workList.SelectedItem.Text==“调查工作”)
lblWork.Text=“好的,夏洛克。”;
else if(workList.SelectedItem.Text==“与人合作”)
lblWork.Text=“与外星人相对?”;
else if(workList.SelectedItem.Text==“需要出差的工作”)
lblWork.Text=“我可以向你展示世界……”;
else if(workList.SelectedItem.Text==“帮助他人”)
lblWork.Text=“你是一个高尚的灵魂。”;
}  
//查找用户单击的图像的哪个部分的分数
public void ImageButton\u单击(对象发送者,ImageClickEventArgs e)
{
如果((e.X>2&&e.X<87)和(&&e.Y>2&&e.Y<120))
m_imageScore=50;
否则如果((e.X>96&&e.X<212)和(e.Y>1&&e.Y<89))
m_imageScore=25;
否则如果((e.X>2&&e.X<87)&(e.Y>121&&e.Y<211))
m_imageScore=10;
否则如果((e.X>124&&e.X<212)和(e.Y>94&&e.Y<218))
m_imageScore=5;
}
//查找复选框列表的分数
公共无效复选框列表(对象发送者、事件参数e)
{
foreach(CheckBoxlist1.Items中的ListItem项目)
如果(选定项)
{
m_分数=Int32.Parse(item.Value)+m_分数;
}
}
//查找剩余列表的分数
公共无效按钮CLICK1(对象发送方,事件参数e)
{
m_分数=textComments.Text.Length+m_分数;
m_score=Int32.Parse(DropDownList1.SelectedItem.Value)+m_score;
m_score=Int32.Parse(RadioButtonList1.SelectedItem.Value)+m_score;
m_score=Int32.Parse(workList.SelectedItem.Value)+m_score;
int final_score=m_score+m_imageScore;
如果(最终得分>100)
lblresults.Text=“你是一个外向的性格类型。”;
否则如果(最终分数>100和最终分数25)
lblresults.Text=“你是一个普通的全能人士。”;
否则如果(最终分数为0)
lblresults.Text=“你是个害羞的人,不是吗?”;
}
人格测验




选择性别:

最喜欢的季节:
春天 夏天 落下 冬天

以下哪种颜色是您最喜欢的? 红色 蓝色 紫色 黄色的 绿色 橙色 紫罗兰色 粉红色 棕色的 灰色

你喜欢哪种类型的工作?
办公室工作 户外工作 调查工作 与人共事 需要出差的工作 帮助他人


你喜欢哪种食物(尽可能多地选择) 面包 胡萝卜 冰淇淋 薯片 糖果棒 芝士蛋糕 牛排 软饮料 牛奶 意大利面 披萨 奶酪 杏树 布朗尼 苹果 橘子 瓜类 豌豆 球芽甘蓝 沙拉 金枪鱼

哪张图片最吸引你?








请尝试使用开关,而不是使用if语句来确定所选项目。这将给你更多的控制,因为你可以有多个案例失败,并设置一个默认值

我认为你的主要问题是你的得分。看看你的第二次得分检查:

else if (final_score > 100 && final_score <50)

else if(final_score>100&&final_score什么不起作用?“有时起作用,有时不起作用”既不能为我们提供足够的信息说明应该发生什么,也不能说明如何失败。请定义“有时不起作用”。如果我们不知道您使用的逻辑,我们就不可能知道是否存在逻辑错误。我们既没有输入也没有预期的输出,只是代码块太大了。我建议您设置断点并手动调试角落案例,以了解发生了什么事。也许您尝试测试的个性就是问题所在。这一点是的。我把我的极限搞错了。谢谢你也指出了我没有涵盖大于或等于/小于等于数字的事实。帮了大忙!谢谢!
if (final_score > 100)
    lblresults.Text = "You are an outgoing personality type.";
else if (final_score <= 100 && final_score > 50)
    lblresults.Text = "You are a merry soul.";
else if (final_score <= 50 && final_score > 25)
    lblresults.Text = "You are a regular kind of all-around person.";
else if (final_score <= 25 && final_score >= 0)
    lblresults.Text = "You are a shy one, aren't you?";