I'm having problem with a simple C program. Even if I enter a year between 1000 and 1999 it still displays invalid year. Please tell me what's happening??
#include <stdio.h>
main()
{
int year;
c:
printf("\n\nEnter a Year: ");
scanf("%d", year);
if ((year < 1000) || (year > 1999))
{
printf("\n\nInvalid Year");
goto c;
}
convert(year);
}
convert(int year)
{
printf("%d", year);
}
You need to pass an address to scanf, i.e.:
scanf("%d", &year);
Note the ampersand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With