The program written below runs perfectly upto some extent but the output varies............because the compiler prints the "{Enter the value}" line twice and itself adds a positive number in the counter..................


int main()
	int sum1=0,sum2=0,sum3=0;
	char value,alpha;
		printf("\n Enter the value");
		else if(alpha>0)
			sum2=sum2+1;  // for positive
		else if(alpha<0)
	printf("\n The zeros are %d", sum1);
	printf("\n the positive are %d", sum2);
	printf("\n the negative are %d",sum3);

>>because the compiler prints the
Don't blaim the compiler for the code you wrote :) The logic of your program is flawed.

scanf("%c" expects you to enter an alphabetic character, such as 'D'. The switch statement is checking for numeric data, such as 0, 1, 2, ... Since you used scanf( with %c that switch statement must check for the numeric values of the character, such as '0', '1', '2' etc. Note that using < and > doesn't mean much with that because, if you look at any ascii char you will see that there are NO characters < 0 and they are all > 0. Finallly, its ot possible to eter a negative value with %c.


Like Ancient Dragon said, it looks like you declared a switch statement which is looking for numbers ( ==0, less than, and greater than 0) but your input method is asking for a character.

What you should do is change the input to int, and actually let the while loop preform without making it "Not equal to" whichever number or letter.

What about instead of not D, using :


With that, whenever the user is done, they can press cntrl+Z then enter to end the loop?

This question has already been answered. Start a new discussion instead.