Click here to Skip to main content
13,793,706 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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.
Posted 10-Aug-18 0:32am
Updated 10-Aug-18 1:35am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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;
   }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.181207.3 | Last Updated 10 Aug 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100