function that takes care of turn

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • timbomo
    New Member
    • Mar 2010
    • 2

    function that takes care of turn

    i dont know of a better way to write this i am stuck. i want to tell the user whose turn it is : i get this error

    error: expected `:' before ';' token

    for this code below

    Code:
    int turn_it_is(int play1, int play2)
    {
        cout << (((play1%2)==1)((play1:play2));
        cout <<  " it's your turn ";
        cin >> turn_it_is;
    }
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    I think you're missing the question mark, and the options shouldn't be encased together in parentheses.

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      As jkmyoung says:
      The ternary operator or conditional expression operator is:
      condition ? expression1 : expression 2
      e.g. min=(x<y?x:y) //min would be assigned the value of x if x<y else min=y

      Comment

      • sridhard2406
        New Member
        • Dec 2007
        • 52

        #4
        you can use this ternary operation on above line of cout, store the output on temperary variable, and write the the cout.

        Comment

        • Dheeraj Joshi
          Recognized Expert Top Contributor
          • Jul 2009
          • 1129

          #5
          What is
          Code:
          turn_it_is
          in the above code? And you need to fix the ternary operator.

          Regards
          Dheeraj Joshi

          Comment

          Working...