Ok, I have been looking online, but I can't find any help for my limited knowledge so far in my course.
I am making a basic program that you input an integer for month and one for day. I have it set up already to give an error if it is beyond the limit of how many months their are and days in a month (exluding Feb special rules). The tricky part though is making the "if statements" verify that the input from the user isn't a decimal number.
While looking online I could find solutions pertaining while loops and all these other commands I am not supposed to have learned yet, so I shouldn't use them. All I have at my disposale are basic arguments within if statements.
My code so far:
Code:
#include <stdio.h>
int main()
{
int month, day;
printf("Enter a month (use a 1 for Jan, etc.): ");
scanf("%d", &month);
printf("Enter a day of the month: ");
scanf("%d", &day);
if (month < 1 || month > 12 || month%1 != 0)
printf("Interger for month entered was %d and is an invalid entry", month);
else if (day < 1 || day > 31 || day%1 != 0)
printf("Interger for day entered was %d and is an invalid entry", day);
else {
printf("The month entered was %d and the day of the month %d", month, day);
}
return 0;
}
I was trying to use the modular command to check for a remainder, but when I run the program I am getting:
[cameron@localhost Program4]$ make Exercise2
cc Exercise2.c -o Exercise2 //No Errors from Compiler
[cameron@localhost Program4]$ ./Exercise2
Enter a month (use a 1 for Jan, etc.): 1
Enter a day of the month: 2
The month entered was 1 and the day of the month 2 //Normal run that works
[cameron@localhost Program4]$ ./Exercise2
Enter a month (use a 1 for Jan, etc.): 1.2 //Trying to input decimal number
Enter a day of the month: Interger for day entered was 0 and is an invalid entry[cameron@localhost Program4]$ //Says Integer for day was 0 and shuts down.