So, initially I did this if-else nested in a while loop to add all the squares of the odd numbers between to numbers. For example, if it the two numbers were 10 and 20, the sum of the squares of the odd numbers would be 1165 (11^2 + 13^2 + 15^2 ...). So, now I want to use a for loop instead of a while loop. I've seen other examples, but I can't implement with mine since it's only my second with working with C.
The following is the while loop and the print statement for the answer (I made "i" = firstNum, so firstNum wouldn't change in value, and firstNum and secondNum is just input from the user):
i = firstNum;
while (i <= secondNum) {
// checks if number is odd or even
if (i % 2 != 0) {
sumOdds += i * i;
i += 2;
}
else {
++i;
}
}
printf("\n");
printf("Sum of the squares of odd integers between %d and %d = %d\n", firstNum, secondNum, sumOdds);