3 Replies - 208 Views - Last Post: 17 February 2013 - 04:00 PM Rate Topic: -----

#1 geo r.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-June 12

if statement

Posted 17 February 2013 - 03:36 PM

Hello
I am receiving an "unreachable code error" in the following:

   if (customer != "I"
                && customer != "R"
                && customer != "C");
            {
                MessageBox.Show("Please Enter I for Industrial, R for Residential, or C for Commercial.");
                txtCustomer.Focus();
                return;
            

I am fairly new to C# and not sure how to continue.
I have tried using "&", "==" and combinations thereof.
Thanks
Geo r.

Is This A Good Question/Topic? 0
  • +

Replies To: if statement

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: if statement

Posted 17 February 2013 - 03:40 PM

Remove the semi-colon at the end of the if statement :)
Was This Post Helpful? 0
  • +
  • -

#3 geo r.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-June 12

Re: if statement

Posted 17 February 2013 - 03:44 PM

Thanks
I was looking at it for so long, my eyes just glazed over it
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5464
  • View blog
  • Posts: 11,731
  • Joined: 02-June 10

Re: if statement

Posted 17 February 2013 - 04:00 PM

You should also make this case independent.
"I" != "i"

if (customer.ToLower() != "i" && // blah blah blah



Also consider what happens when your menu gets 20 items long.
Do you really want this long 20+ item list of 'or' statements? Yuck!
And what if they enter "industrial"? Wouldn't it be nice if the program still handled that as "i"?

string validMenuOptions = "irc";
if (!validMenuOptions.contains(customer[0].ToLower())
{
    // Yell at user for not entering a good value
}



My next thought is that having the textbox and submit button at all is just a pain ugly and very Windows 3.5. Why not put in a ComboBox with a set of valid options? Or a menu in the menubar?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1