The below code gives a compiler error:--> rough.cpp:6:30: error: operands to ?: have different types 'short int' and 'const char*'
int main() {
for (short i {10}; i <= 100; i += 10) {
cout<<((i % 15 == 0) ? i : "-")<<endl;
}
return 0;
}
This code compiles without any error or warning:
int main() {
for (short i {10}; i <= 100; i += 10) {
cout<<((i % 15 == 0) ? i : '-')<<endl; // error line
}
return 0;
}
And shows the below output:
45
45
30
45
45
60
45
45
90
45
Can anybody please explain what's happening and what's the difference between the two ?
As I want the expected output to be:
-
-
30
-
-
60
-
-
90
-