A
Apotheosis
The problem professor gave us is:
Write a program which reads two integer values. If the first is less
than the second, print the message "up". If the second is less than
the first, print the message "down" If the numbers are equal, print
the message "equal" If there is an error reading the data, print a
message containing the word "Error" and perform exit( 0 );
And this is what I wrote:
main()
{
int x;
int y;
printf("Enter the first integer: ");
scanf("%d", &x);
printf("Enter the second integer: ");
scanf("%d", &y);
if (x > y)
{
printf("Up");
}
else
{
if (x < y)
{
printf("Down");
}
else
{
if (x = y)
{
printf("Equal");
}
else
{
printf("Error");
getch();
exit (0);
}
}
}
}
Works fine at first, but whenever I enter invalid characters such as
!, A, %, :, etc. It never asks me for the second integer and skip to
printf("Down");
Can anyone be kind enough to explain to me why that happened?
Write a program which reads two integer values. If the first is less
than the second, print the message "up". If the second is less than
the first, print the message "down" If the numbers are equal, print
the message "equal" If there is an error reading the data, print a
message containing the word "Error" and perform exit( 0 );
And this is what I wrote:
main()
{
int x;
int y;
printf("Enter the first integer: ");
scanf("%d", &x);
printf("Enter the second integer: ");
scanf("%d", &y);
if (x > y)
{
printf("Up");
}
else
{
if (x < y)
{
printf("Down");
}
else
{
if (x = y)
{
printf("Equal");
}
else
{
printf("Error");
getch();
exit (0);
}
}
}
}
Works fine at first, but whenever I enter invalid characters such as
!, A, %, :, etc. It never asks me for the second integer and skip to
printf("Down");
Can anyone be kind enough to explain to me why that happened?