C programming using Codeblocks from giving error in the programming below

Asked

Viewed 31 times

-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;
}

1 answer

2

The ternary operator may produce only one value and not an instruction.

Soon instead of:

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

Must be:

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

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

Example of code with these changes in Ideone

Browser other questions tagged

You are not signed in. Login or sign up in order to post.