我做的在C#中的一些自我教育,虽然我做了更复杂的项目比这个,我想不通的问题是什么。分割两个数字
private void button4_Click(object sender, EventArgs e)
{
int headcount = 0;
int input = Global.inputcount;
for (int i = 0; i < Global.inputcount; i++)
{
if (Global.myTextFile[i] == "F")
{
headcount++;
}
}
float result;
result = headcount/input; <<< that line
button4.Text = result.ToString();
}
这是我的代码,它应该算多少次的myTextFile
阵列中F
occour,应该除以数量与输入数量。
我调试了很多次,和一切都很好,直到[是]线。尽管(人数=〜2201)和(输入=〜4321),结果为0。
我用帕斯卡,我一直在使用C#像2个月所以如果有人能帮助我,我将不胜感激工作。
F
在匈牙利
这是一个整数除法,使用result =(float)headcount/input;代替。 –
问题是整数除法。尝试转换为'result =(float)headcount/input;' –
'int/int' ='int' - 您需要将devisee('headcount')投射到'float' – Olipro