0

Hey I just started to program so I dont know how to fix it. Here is my code:

if(f_1 == 'x' && f_2 == 'x' && stupid < '80' ) 
       {
              f_3 == 'o';
              player_turn = '1';

              }
       else if(f_2 == 'x' && f_3 == 'x' && stupid < '80')

              {
              f_1 == 'o';
              player_turn = '1';
              }
  ...

But i dont know why he dont give errors here:

 if (eingabe == '1' && f_1 == '1' && player_turn == '1' )
    {
        f_1= 'x';
        player_turn = '2';
        cout << "Spieler Zwei ist am Zug" <<endl;
    }
    else if (eingabe == '2' && f_2 == '2' && player_turn == '1') {
        f_2= 'x';
        cout << "Spieler Zwei ist am Zug" <<endl;
            player_turn = '2';
        } 

...

Isnt it the same Problem here. I googled about it but I dont understand where i did mistakes in "" and ''

Wendler
  • 11
  • 1
  • 1

3 Answers3

2

'80' is a valid multicharacter constant, but most probably not what you want. Thus the compiler warns you about this.

"But i dont know why he dont give errors here:"

I can't tell from your context, what you're actually trying to achieve, but

if (eingabe == '1' && f_1 == '1' && player_turn == '1' )

the character constants in your second sample are all fine.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
1

Your problem is in the below code

stupid < '80'

Assuming stupid is of type char, the value should be single char. '80' is not a valid single-character literal, it's a multi-char literal, which is probably you don't want.

OTOH, in the second snippet, all the character literals are single character constants and hence, it's correct and no warning is produced.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
1

Single quotes '' are used for character literals (i.e., one character), and double quotes "" for string literals (array of characters, terminated with NUL/zero). The problematic multi-character literal is '80' - you have two characters inside single quotes.

Arkku
  • 41,011
  • 10
  • 62
  • 84