2 Replies - 1775 Views - Last Post: 26 January 2010 - 11:40 PM Rate Topic: -----

#1 cdh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 19-January 10

Why is my "else if" statements not working?

Posted 26 January 2010 - 10:36 PM

I'm learning here....

it's telling me my "else if" is an "invalid expression term" and I am not sure what I'm doing wrong. I'm stumped

EDIT: I figured it out!!! Fix is below...now on to the rest!

EDIT2: nevermind, tons of errors...going to bed now. Tomorrows another day...hopefully a better one

		private void disPercent() 
		{
			char cutomerType = char.Parse(typeBox.Text);
			double subTotal = double.Parse(subBox.Text);
			double dscntAmnt = (subTotal * percntOff);
			double totalAmnt = (subTotal - dscntAmnt);
			double percntOff;

			if (cutomerType == "R") & (subTotal >= 250);
				percntOff = .25;
			else if (cutomerType == "C") & (subTotal < 250);
				percntOff = .20;
			else (cutomerType != "C") & (cutomerType != "R");
				percntOff = .4;
			percentBox.Text = percntOff.ToString();
			
			
		}


		private void disPercent() 
		{
			char cutomerType = char.Parse(typeBox.Text);
			double subTotal = double.Parse(subBox.Text);
			double percntOff;
			
			if (cutomerType == "R")
			{
				(subTotal >= 250);
				percntOff = .25;
			}

			else if (cutomerType == "C")
			{
				(subTotal < 250);
				percntOff = .20;
			}
			else (cutomerType != "C") & (cutomerType != "R");
				percntOff = .4;
			percentBox.Text = percntOff.ToString();
			
			
		}

This post has been edited by cdh: 26 January 2010 - 11:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Why is my "else if" statements not working?

#2 pareidolia  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 38
  • Joined: 17-September 09

Re: Why is my "else if" statements not working?

Posted 26 January 2010 - 11:30 PM

All the comparisons are contained between the parenthesis, you don't put a semi-colon on the end of the comparison statement and use && for "and" || for "or". Also, else does not have any comparison statements. That code is run if no other comparisons match (i.e. customType = "T").
if (cutomerType == "R" && subTotal >= 250)
{
	  percntOff = .25;
}
else if (cutomerType == "C" && subTotal < 250)
{
	  percntOff = .20;
}
else
{
	  percntOff = .4;
}


Was This Post Helpful? 0
  • +
  • -

#3 cdh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 19-January 10

Re: Why is my "else if" statements not working?

Posted 26 January 2010 - 11:40 PM

Thank you for the explanation! I wasted so much time trying to figure this out. Can't wait until I'm some what understanding this more.

Side note: I previously had the && but when I was going though my code trying to figure what was wrong I backed that out and forgot to put it back in!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1