A
A
Atlass2020-03-22 13:47:58
C++ / C#
Atlass, 2020-03-22 13:47:58

How to make sure that out of several conditions only one suitable one is met?

I wrote this code:

if (num1 == 1 && num11 ==1){
    alert ('тест1');
  }
  if (num2 == 1 && num11 == 1){
    alert('тест2');
  }

But I get 2 alerts, but all num, at the same time, cannot be equal to 1. How can I make only one condition work?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir S, 2019-08-25
@SkrinV

if (Input.GetKeyDown ("E") ) //метод возвращает bool - в с# его нельзя сравнивать с 0
        {
            Guns += 1;
        }
        if (Input.GetKeyDown ("Q") ) //В чём ошибка?
        {
            Guns -= 1;
        }

W
WapSter, 2020-03-22
@Atlass

if (num1 == 1 && num11 ==1 && num2 != 1){
    alert ('тест1');
  }
  if (num2 == 1 && num11 == 1 && num1 != 1){
    alert('тест2');
  }

Well, like so, but the code is not very good at all.
if (num1 == 1 && num11 == 1){
    alert ('тест1');
} else if (num2 == 1 && num11 == 1){
  alert('тест2');
}

It's more correct, but the code is still shitty)

M
McBernar, 2020-03-22
@McBernar

If you have num1 equal to 1 and num2 not equal to 1, then there will be no two alerts.
Well, yes - ===, not ==.

R
rasschitai, 2020-03-22
@rasschitai

num*** is it a number or a string?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question