I typed a program in C using the switch control expression.
This is to determine if an integer is odd or even, and I keep getting this warning in Code::Blocks in the lines with "num % 2 == 0;" and "num % 2 != 0;".
warning: statement with no effect [-Wunused-value]|
I have tried to google the issue, but each solution appears vague, like one stated that the problem lies with assigning a value to the result.
The program is below:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
printf("Enter the integer\n");
scanf("%d", &num);
switch(num % 2)
{
case 0:
num % 2 == 0;
printf("Number is even");
break;
case 1:
num % 2 != 0;
printf("Number is odd");
break;
}
Return 0;
}
It means exactly what your compiler tells you: The statements
num % 2 != 0;
and
num % 2 == 0;
do not have an effect and can be removed. These are comparisons, but the comparison result is not used (i.e. discarded).
The conditional is already here:
switch(num % 2)
and the result is used with the case statements.
Maybe the statements without any effect were meant to be comments? Then prefix them with //.