I have a for loop in which I placed several if statements. The objective of these conditionals is to check divisibility of a number and then output a string if the number is divisible by 3. If the number is divisible by 5, another string will be outputted. However, if the number is divisible by both 3 and 5, an entirely different string will be outputted in its place instead of the other strings.
Here is my code:
for (i = 1; i <= file_int; i++){
if (i % 3 == 0) {
printf("Hoppity \n");
}
if (i % 5 == 0) {
printf("Hophop \n");
}
if (i % 5 == 0 && i % 3 == 0) {
printf("Hop \n");
}
}
As you can see, the last conditional doesn’t quite work. What type of control construct should I use? else?
Thanks alot.
1 Answer