C# 如何将分数和总数相加?

C# 如何将分数和总数相加?,c#,C#,当用户单击“添加分数”菜单项时,将每种饮料的分数添加到饮料总数中,清除文本框,然后重置焦点 我一直在想如何添加上面引用的内容。我认为我想得太多了,让事情变得比实际情况更难 以下是我迄今为止所做的工作: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System

当用户单击“添加分数”菜单项时,将每种饮料的分数添加到饮料总数中,清除文本框,然后重置焦点

我一直在想如何添加上面引用的内容。我认为我想得太多了,让事情变得比实际情况更难

以下是我迄今为止所做的工作:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Lab6
{      
public partial class NewTester : Form
{
    private int AppleAde;
    private decimal TotalScore;
    private string Winner_Name = ""; 
    int PrunePunch_Score;
    int Total_Num_Of_Tasters;
    decimal Average_Rating_Of_Each_Drink;
    //private decimal Total_Score;
    public NewTester()
    {
        Thread t = new Thread(new ThreadStart(SplashStart));
        t.Start();
        Thread.Sleep(5000);
        InitializeComponent();

        t.Abort();
    }

    public void SplashStart() {
    Application.Run(new Form2());
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
        this.Close(); 
    }

    private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Lab6 by J Soto \nThis lab was started on 10/9/13","About Lab 6",MessageBoxButtons.OK);
    }

    private void addYourScoresToolStripMenuItem_Click(object sender, EventArgs e)
    {   // Vars for text box values...
        PrunePunch_Score = Convert.ToInt32(PrunePunchTextBox.Text);
        AppleAde = Convert.ToInt32(AppleAdeTextBox.Text);


        //...
        if ((PrunePunch_Score <= 10) && (PrunePunch_Score >= 0))
            Convert.ToInt32(PrunePunchTextBox.Text);


        else
            MessageBox.Show("Please enter a number between 0 and 10","Prune Punch");
        if ((AppleAde <= 10) && (PrunePunch_Score >= 0))
            Convert.ToInt32(AppleAdeTextBox.Text);

        else
            MessageBox.Show("Please enter a number betwen 0 and 10","Apple Ade");

       //...



    }

    private void PrunePunchTextBox_TextChanged(object sender, EventArgs e)
    {
        PrunePunch_Score = Convert.ToInt32(PrunePunchTextBox.Text); 
    }

    private void AppleAdeTextBox_TextChanged(object sender, EventArgs e)
    {
        AppleAde = Convert.ToInt32(AppleAdeTextBox.Text);

    }

    private void summaryToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string Summary;

       // Summary= "Winner:"+ Winner_Name "Total Number of Taste Testers:" + Total_Num_Of_Tasters "Average rating for each drink:" + Average_Rating_Of_Each_Drink; 


    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用系统线程;
名称空间Lab6
{      
公共部分类:形式
{
私人int AppleAde;
私人十进制总分;
私有字符串赢家_Name=“”;
int PrunePunch_分数;
品酒师总数;
每种饮料的十进制平均值;
//个人十进位总分;
公共图书馆
{
螺纹t=新螺纹(新螺纹起点(飞溅起点));
t、 Start();
睡眠(5000);
初始化组件();
t、 中止();
}
公共空间启动(){
Application.Run(新Form2());
}
私有void Form1\u加载(对象发送方、事件参数e)
{
}
private void exitToolStripMenuItem\u单击(对象发送者,事件参数e)
{
这个。关闭();
}
private void aboutToolStripMenuItem\u单击(对象发送者,事件参数e)
{
MessageBox.Show(“J Soto的Lab6\n该实验室于2013年9月10日启动”,“关于实验室6”,MessageBox按钮.OK);
}
私有void addYourScoresToolStripMenuItem\u单击(对象发送者,事件参数e)
{//文本框值的变量。。。
PrunePunch_Score=Convert.ToInt32(PrunePunchTextBox.Text);
AppleAde=Convert.ToInt32(AppleAdeTextBox.Text);
//...
如果((删节分数=0))
转换为32(PrunePunchTextBox.Text);
其他的
MessageBox.Show(“请输入一个介于0和10之间的数字”,“修剪打孔”);
如果((AppleAde=0))
转换为32(AppleAdeTextBox.Text);
其他的
MessageBox.Show(“请输入一个介于0和10之间的数字”,“苹果Ade”);
//...
}
私有void PrunePunchTextBox\u TextChanged(对象发送方,事件参数e)
{
PrunePunch_Score=Convert.ToInt32(PrunePunchTextBox.Text);
}
私有void AppleAdeTextBox_TextChanged(对象发送方,事件参数e)
{
AppleAde=Convert.ToInt32(AppleAdeTextBox.Text);
}
私有void summaryToolStripMenuItem\u单击(对象发送方,事件参数e)
{
字符串摘要;
//Summary=“Winner:“+Winner\u Name”试酒师总数:“+Total\u Num\u\u品尝师”每种饮料的平均评分:“+每种饮料的平均评分”;
}
}

}嗯,这是个大问题。我将指出,您正在调用
Convert
,而没有存储返回的值

您有类似于
Convert.ToInt32(PrunePunchTextBox.Text)的功能
而不是
var value=Convert.ToInt32(PrunePunchTextBox.Text)


希望有帮助

不要在表单开头声明int。只需拖放一个从0开始的标签。每个分数加起来。将标签转换为整数,并使用+=为其添加值


(顺便问一下,你的项目有rar我可以处理吗?

有带“/”的代码,因为我不想在处理作业时删除它。因此,如果我不需要它,我将稍后删除它。您可以使用
+
添加它。至于其他人,不清楚你有什么问题。另外,请考虑阅读。我已经编辑了你的书名。请看,“,其中的共识是“不,他们不应该”。我的意思是说,你如何不断增加结果。如果结果是2,我按下add(添加)菜单项,它会在上面添加另一个数字。例如:我有2张,然后输入4张,然后再次单击菜单项,结果是6张……有点像在选举中添加选票,我想看看哪个果汁品牌获得最多的选票。他已经宣布他们在品酒师总数中名列前茅@galleryguy——至少有两个案例是他忘了做作业。我的意思是说你是如何不断增加结果的。如果结果是2,我按下add(添加)菜单项,它会在上面添加另一个数字。例如:我有2张,然后键入4,然后再次单击菜单项,结果是6张……有点像在选举中添加选票,我想看看哪个果汁品牌获得最多的votesI,如果你愿意,我可以制作一张。