Code:
#include<stdio.h>
#include<conio.h>
int dayspassed(int month, int day, int year,
int smonth, int sday, int syear);
struct library
{ char bno[80];
char btit[80];
char author[80];
};
int main()
{ char buffer[20]={0};
int day=0, month=0, year=0;
int sday=0, smonth=0, syear=0;
struct library book1;
clrscr();
puts("Please enter the book number: ");gets(book1.bno);
puts("Please enter the book title: ");gets(book1.btit);
puts("Please enter the book author/s: ");gets(book1.author);
puts("Please enter the date borrowed in MM/DD/YY format: ");
fgets(buffer, sizeof(buffer), stdin);
sscanf(buffer, "%d/%d/%d", &month, &day, &year);
if((month>12||day>30))
{puts("Error!: Invalid date.\n");
printf("\nThe program will exit!");
exit();}
else
printf("\nYou chose %d/%d/%d\n", month, day ,year);
puts("Input date returned in MM/DD/YY format: ");
fgets(buffer, sizeof(buffer), stdin);
sscanf(buffer, "%d/%d/%d", &smonth, &sday, &syear);
if((smonth>12||sday>30))
{puts("Error!: Invalid date.\n");
printf("\nThe program will exit!");
exit();}
clrscr();
printf("\n\n\n\t\t\tThe days between %d/%d/%d and %d/%d/%d is %d",
month, day, year, smonth, sday, syear,
dayspassed(month, day, year, smonth, sday, syear));
printf("\n\t\t\tBook Number is: ");puts(book1.bno);
printf("\n\t\t\tBook Title is: ");puts(book1.btit);
printf("\n\t\t\tBook Author: ");puts(book1.author);
printf("\n\t\t\tDate Borrowed: %d/%d/%d",month, day, year);
printf("\n\t\t\tDate Returned: %d/%d/%d",smonth, sday, syear);
if((dayspassed(month, day, year, smonth, sday, syear)<4))
{printf("\n\nYou have no fine, please return the book to its proper shelf");
}
else((dayspassed(month, day, year, smonth, sday, syear)>4||
dayspassed(month, day, year, smonth, sday, syear)<30));
{printf("\n\nYour fine is %d, please return the book to its proper shelf",
((dayspassed(month, day, year, smonth, sday, syear))*5));
getch();}
if(dayspassed(month, day, year, smonth, sday, syear)>30);
{puts("\n\nPress any key to continue.");
printf("\n\nP.S. You also have a notice!, bye!");}
getch();
}
int dayspassed(int month, int day, int year,
int smonth, int sday, int syear)
{ int diffday=0, diffmonth=0, diffyear=0;
int days=0;
diffday=sday-day;
diffmonth=smonth-month;
diffyear=syear-year;
days=diffday+(diffmonth*30)+(diffyear*360);
return(days);
}