Siya Siya - 1 month ago 5
C Question

Where did i make a mistake in my program i think its a logical error but i cant quite find it

so i have this program that i wrote it complies yeah but i don't think it outputs correctly did i make a mistake here ...?
Here's my program

#include <stdio.h>

void main(void)
{

int loop_counter = -8;
int user_input = 9;
char c1 = '9';
char c2 = 43;

while(loop_counter != 21);
{

printf("%d\n", loop_counter);
printf("%d\n", loop_counter+1);
printf("%d\n", loop_counter+2);


loop_counter = loop_counter + 1;
loop_counter++;

printf("%d\n", loop_counter);
printf("%d\n", loop_counter+1);
printf("%d\n", loop_counter+2);



getchar();

}

printf("loop exit\n\n");
getchar();

}

Answer

The biggest error is

while(loop_counter != 21);

where the trailing ; will make the loop infinite.

Comments