C
C
CodeInside2015-11-01 20:26:01
C++ / C#
CodeInside, 2015-11-01 20:26:01

How to write goto in ternary operator?

bool fiftyOnFifty = true;//подсказка "50/50"
getAnswer: cout << "\nInput symbol of answer: ";
    cin >> userAnswer;

    if(!((userAnswer >= '1' && userAnswer <= '3') || (userAnswer >= 'a' || userAnswer <= 'd')))//пользователь должен ввести символ с диапазонов '1'-'3' и 'a'-'d'
    {
      goto getAnswer;
    }

    if(userAnswer == '1')//если пользователь выбрал подсказку "50/50"
    {
      (fiftyOnFifty) ? fiftyOnFiftyFunc() : goto getAnswer;
    }

The compiler complains about goto. It says "expression required". Replacing the ternary operator with if is not a hunt. Or well, what for this label and replace it with a function?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-11-01
@Rsa97

The use of goto is bad manners.

do {
    cout << "\nInput symbol of answer: ";
    cin >> userAnswer;
    if (userAnswer == '1') {
        fiftyOnFiftyFunc();
    }
} while (userAnswer != '2' && userAnswer != '3' && 
         (userAnswer < 'a' || userAnswer > 'd'));

Y
Yaroslav, 2015-11-01
@torwig

You answered yourself: well, his this mark.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question