Try this slight change to your program, and note the changes and comments.
Code:
#include <stdio.h>
int main(void)
{
int x;
char ch;
printf("Please enter your number: ");
scanf("%d" , &x);
if (x > 0)
printf("Your number is positive!\n");
else if (x < 0)
printf("Your number is negative!\n");
ch = getchar();
printf("%d\n",ch); //here, ch will always equal 10 - a newline
//that is left over from entering x. We can use it, however.
while (ch) //ch will always be true on the first loop
{
printf("Enter another number?\n");
scanf(" %c", &ch); //note the space before the %c! That space causes scanf
//to "eat" whitespace in the keyboard (stdin) buffer.
if (ch=='y') //so now ch is correct
{
printf("Please enter your number: ");
scanf("%d" , &x);
if (x > 0)
printf("Your number is positive!\n");
else if (x < 0)
printf("Your number is negative!\n");
}
else
break; //ch not equal to 'y'
}
printf("Thank u for using my software, good bye!\n");
getchar();
return 0;
}
Your problem is a very common one. getchar() or scanf("%c"...) without a space before the %c, will ALWAYS take a waiting newline char from the stdin, and use it for a char input - because a newline is what it's looking for.
Integers don't have that problem, since they have a different size than char's have.