Oscar Apeland
Oscar Apeland

Reputation: 6662

IF-Statement ignores last criteria

So I have a bunch of input textfields to calculate some stuff. These are doubles. I want that every time its not all filled in, it will display "Please enter all values" Below mentioned code does this for all fields, except the last one, here nitrogen. If i change them around to make another variable last this does not work. Instead it just makes the app give the result when the last field is entered.

So for example, no fields got a value, but when I type something into nitrogen it gives me the result. If I type something else into any of the other fields (Nitrogen blank) i get the correct message "Please enter all values."

How do I make it account for all fields, not just all except the last one?

if (temprature,methane,ethane,propane,nbutane,ibutane,oxygen,npetane,ipetane,nhexane,nitrogen == 0)
{
    outputText.text = @"Please enter all values";
} else
{


    outputText.text = resultString;

}

Upvotes: 0

Views: 77

Answers (1)

emillime
emillime

Reputation: 531

Try this, this should work if any of the fields are empty.

if (temprature == 0 || methane == 0 || ethane == 0 || propane == 0 || nbutane == 0 || ibutane == 0 || oxygen == 0 || npetane == 0 || ipetane == 0 || nhexane == 0 || nitrogen == 0)
{
    outputText.text = @"Please enter all values";
} else
{
    outputText.text = resultString;
}

Upvotes: 1

Related Questions