With my code below how would I either ignore or remove decimal numbers? I tried typecasting it but that messed up my code. I can't think of any way to make a loop to accept only integers either :(. I don't understand why the scanf is accepting decimal numbers when I am using %d and I declared my variables as ints. Any ideas would be greatly appreciated :).
#include <stdio.h>
int main (void)
{
int x , y;
int z;
printf("Please enter a value for x:\n");
printf("x: ");
scanf("%d" , &x);
//x = (int) x;
while((x < 0) || (getchar() != '\n'))
{
printf("Please enter interger greater than 0\n");
printf("Please enter a value for x:\n");
printf("x: ");
scanf("%d" , &x);
}
printf("Please enter a value for y:\n");
printf("y: ");
scanf("%d" , &y);
//y = (int) y;
while((y < 0) ||(getchar() != '\n'))
{
printf("Please enter interger greater than 0\n");
printf("Please enter a value for y:\n");
printf("y: ");
scanf("%d" , &y);
}
return 0;
}