+ 1
why that line error?
#include <iostream> using namespace std; int main() { int a= 5; int b= 55; int c= 555; int d= (c%b) > (c%a)?5:55; int e= (c%b) > (c%a); //int f= 5:55; <---- error cout << d << endl ; cout << "c%b = " << c%b << endl ; cout << "c%a = " << c%a << endl ; cout << "((c%b) > (c%a)) = " << ((c%b) > (c%a)) << endl ; cout << "e = " << e << endl ; //cout << "5:55 = " << f << endl ;< --- //error return 0; }
2 Answers
+ 3
Because you are trying to use ":" without "?"
the syntax is as below
int f = (boolean logic) ? valueIfTrue : valueIfFalse;
If this answer is not you expected then you will have to specify what exactly you are trying to assign to "f" variable?
+ 1
Thank you verymuch Milind. i'm get it now.