Hello everyone!
My name is Or Ellenbogen and im new to the C language (also my first language) and to this community
I bought myself a book from the local bookstore to start learning the language and today I faced my first problem while created a very simple and basic program for practice.
The target of the program is to ask the user to input a number > \ < 0 and tell him if it is positive or negative, and after doing so - ask him if to repeat the process.
After running the program I noticed my loop is stuck (the while loop I guess) and can't get the getchar(); command right.
Here's the code:
Code:
#include <stdio.h>
void main()
{
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");
while (x > 0 || x < 0) {
printf("Enter another number?\n");
ch = getchar();
getchar();
}
if (ch='y') {
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
printf("Thank u for using my software, good bye!\n");
flushall();
getchar();
}
I'll appreciate your help very much
thank you !