How to Get an Even Number in CPP
- 1). Right-click the CPP file that you want to use to perform the calculation. Click "Open With" and select your preferred C++ editing software.
- 2). Create a decimal data type variable to retrieve the results of the modulus operation. This variable is what you use to detect if the number is an even number. The following code creates a decimal variable:
float result = 0.00; - 3). Detect if the number is an even number. For instance, the following result variable equates to 0, because 6 is an even number:
result = 6 % 2; - 4). Create the "if" statement that displays whether the number is an even number. The following code displays "True" if the number is even:
if (result == 0) {
printf("True");
}
Source...