-1

Lines 11, 12, 15 and 16 are getting errors: " invalid operands of types int and const char[2] to binary operator<< " (I removed the "`" so it wouldn't display it code format).

#include<iostream>

using namespace std;

int main(){

int md,dg,dd,mg,m,d;
cin >> md >> dg >> dd >> mg;

if (dd+dg==md+mg){
   cout << (mg>dg) ? 0 : 1 << " ";
   cout << (dg>mg) ? 0 : 1 << endl;
}
else{
      cout << (mg+md>dd+dg) ? 0 : (dd+dg-mg-md) << " ";
      cout << (dg+dd>md+mg) ? 0 : (md+mg-dg-dd) << endl;
}

system("pause");
}

3 Answers3

7

You need to put parentheses around the ternary expression:

 cout << ((mg>dg) ? 0 : 1) << " ";

Otherwise the input is interpreted as

 cout << (mg>dg) ? 0 : (1 << " ");

due to operator precedence.

vitaut
  • 49,672
  • 25
  • 199
  • 336
  • 1
    Thank you for the fast reply! This has always been bugging me and I thought that it was time to see what the problem was. – Hrvoje Jurić Dec 16 '14 at 20:37
0

All that you are missing is parenthesis around the ternary expression. Following is the fix.

cout << ((mg>dg) ? 0 : 1) << " ";

cout << ((dg>mg) ? 0 : 1) << endl;

cout << ((mg+md>dd+dg) ? 0 : (dd+dg-mg-md)) << " ";

cout << ((dg+dd>md+mg) ? 0 : (md+mg-dg-dd)) << endl;

RcnRcf
  • 356
  • 1
  • 8
0

It should be : cout<<((mg>dg)?0:1)<<endl and similarly for others.