Programming in C using CodeBlocks giving error in programming below [closed]

-2
#include <stdio.h>
#include <stdlib.h>

int main()
{
    float num1 = 10;
    float num2 = 20;

    int resposta;

    num1 < num2 ? printf("Sim/n") : printf("Nao/n");

    num1 < num2 ? resposta = 10 : resposta = -10;

    printf("i%/n", resposta);

    return 0;
}
    
asked by anonymous 17.03.2018 / 00:14

1 answer

2

The ternary operator can only produce a value, not an instruction.

Soon instead of:

num1 < num2 ? printf("Sim/n") : printf("Nao/n");
num1 < num2 ? resposta = 10 : resposta = -10;

It must be:

printf(num1 < num2 ? "Sim\n":"Nao\n");
resposta = num1 < num2 ? 10: -10;

Note that you have \n inverted and written as /n . The same applies to %i in the last printf that was written as i% .

Code sample with these changes in Ideone

    
17.03.2018 / 00:24