Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can somebody plz tell me why the program works for the first two terminals and i

ID: 3567102 • Letter: C

Question

Can somebody plz tell me why the program works for the first two terminals and it stops after.

It doesn't give the right answer even if I put the same terminals twice. ty

#include<stdio.h>

int main()

{

                int const THE_STEP=2;

                int TERM1, TERM2, sum= 0.0 , term;

                char answer;

               

                do{

               

                printf ("Enter the two terminals : ");

                fflush(stdin);

                scanf("%d%d", &TERM1, &TERM2);

               

                term = TERM1;

                while ( term <= TERM2)

                {

                                sum += term;

                                term *= THE_STEP;

                }

                printf(" The sum of the equation is %d ", sum);

               

                printf("Do you want to continue? (y/n) ");

                fflush(stdin);

                scanf (" %c", &answer);

} while ( answer == 'y');

getchar();

return 0;

}

Explanation / Answer

#include<stdio.h>

int main()

{

int const THE_STEP=2;

int TERM1, TERM2, sum= 0.0 , term;

char answer;

do{


sum = 0;
printf ("Enter the two terminals : ");

fflush(stdin);

scanf("%d%d", &TERM1, &TERM2);

term = TERM1;

while ( term <= TERM2)

{

sum += term;

term *= THE_STEP;

}

printf(" The sum of the equation is %d ", sum);

printf("Do you want to continue? (y/n) ");

fflush(stdin);

scanf (" %c", &answer);

} while ( answer == 'y');

getchar();

return 0;

}