使用While循环的数字加法器保持冻结状态. [英] Number adder using a While loop keeps freezing.

查看:67
本文介绍了使用While循环的数字加法器保持冻结状态.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码没有收到任何错误消息,我希望能够将任何数字放入txtNumber教科书中,然后显示当前总数,并可以通过键入"999"退出此循环.当我点击btnCalculate的那一刻 按钮,程序将冻结.不确定如何进行,我们将不胜感激.谢谢


Acidlight

I am not getting any error messages with this code, I was hoping to be able to put any number into my txtNumber textbook, then show the current total and be able to come out of this loop by typing in '999'. At the moment when I click on the btnCalculate button the program freezes. Unsure how to proceed, I would be grateful for any help. Thanks


Acidlight

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

namespace NumberAdder
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            int Total = 0;
            int Number;

            Number = int.Parse(txtNumber.Text);
            

            while (Number !=999)
            {
                Total= Total + Number;
                lblTotal.Text = Total.ToString();
                Number = int.Parse(txtNumber.Text);
                
            }

            MessageBox.Show("All done");
        }

        private void btnEnd_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}


推荐答案

此代码没有收到任何错误消息,我希望能够在txtNumber教科书中输入任何数字,然后显示当前总数,并可以通过键入"999"退出此循环.当我点击btnCalculate的那一刻 按钮,程序将冻结.
I am not getting any error messages with this code, I was hoping to be able to put any number into my txtNumber textbook, then show the current total and be able to come out of this loop by typing in '999'. At the moment when I click on the btnCalculate button the program freezes.


不要发布代码图片,请使用Windows复制和以文本形式发布代码粘贴.
使用插入代码块"将其发布.按钮在论坛编辑器菜单栏上.
没有人会手动输入所有代码来对其进行测试和修改.
但是他们可能愿意复制&如果可以的话,将其粘贴到他们的IDE中.

发布错误对话框等的图像-屏幕捕获更多的任何内容
合适.

您的代码不是冻结"的,它会进入转换和添加的紧密循环
来自文本框的相同值.使用调试器逐步调试,然后
应该看到它一遍又一遍地重复相同的操作.

-韦恩

Don't post pictures of code, post the code as text using Windows copy & paste.
Post it using the "Insert code block" button on the forum editor menu bar.
Nobody is going to type all of your code in manually to test it and amend it.
But they may be willing to copy & paste it into their IDE if they can.

Post images of error dialogs, etc. - anything where a screen capture is more
appropriate.

Your code isn't "freezing", it's going into a tight loop converting and adding
the same value from the textbox. Step through it using the debugger and you
should see it repeating the same operations over and over.

- Wayne


这篇关于使用While循环的数字加法器保持冻结状态.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆