如果价值低于价格,我怎么能弹出一条说“钱不够”的信息? [英] How to can I pop up a message that is saying 'not enough money' when value is lower than price?

查看:56
本文介绍了如果价值低于价格,我怎么能弹出一条说“钱不够”的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我忘了其他的if和它的相关代码

我试图在付费标签上发出错误信息。



继承人我现在代码:

 Double paymet = double.Parse(this.txtTotal.Text); 
Double topay = double.Parse(this.txtCash.Text);
Double FinalTotal;

FinalTotal =付款 - topay;
如果(付款< topay)
{
MessageBox.Show(货币不足);
}





我的尝试:



i使用我的武器库中的所有东西来挖掘它,我仍然没有得到它。

解决方案

首先,不要使用Parse处理用户输入 - 如果他们输入错误,那么你的app崩溃了。请改用TryParse。

其次,C#区分大小写:如果不同,如果

第三,C#要求声明变量,并在整个拼写相同: paymet 不同付款



  double 付款; 
if (!double.TryParse(txtTotal.Text, out payment))
{
...向用户报告错误输入...
return ;
}
double toPay;
if (!double.TryParse(txtCash.Text, out toPay))
{
...向用户报告错误输入...
return ;
}
double finalTotal = payment - toPay;
if (finalTotal < 0 0
{
MessageBox.Show( 资金不足);
return ;
}


你的武器库里有什么东西? if-else(C#参考)| Microsoft Docs [ ^ ]。

ive forgot the else if and its related codes
im trying to make a Error message on paying tab.

heres my current code:

Double paymet = double.Parse(this.txtTotal.Text);
Double topay = double.Parse(this.txtCash.Text);
Double FinalTotal;

FinalTotal = Payment - topay;
If(payment < topay)
{
      MessageBox.Show("Insufficient Money");
}



What I have tried:

i use everything on my arsenal to dig it out, and i still don't get it.

解决方案

First off, don't use Parse to process user input - if they mistype then you app crashes. Use TryParse instead.
Second, C# is case sensitive: If is not the same as if
Third, C# requires variables to be declared, and spelled the same throughout: paymet is not the same as Payment

double payment;
if (!double.TryParse(txtTotal.Text, out payment))
   {
   ... Report bad input to user ...
   return;
   }
double toPay;
if (!double.TryParse(txtCash.Text, out toPay))
   {
   ... Report bad input to user ...
   return;
   }
double finalTotal = payment - toPay;
if (finalTotal < 0.0)
   {
   MessageBox.Show("Insufficient Money");
   return;
   }


Everything in your arsenal? if-else (C# Reference) | Microsoft Docs[^].


这篇关于如果价值低于价格,我怎么能弹出一条说“钱不够”的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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