Library Fine

Library Fine

Your local library needs your help! Given the expected and actual return dates for a library book, create a program that calculates the fine (if any). The fee structure is as follows:
  1. If the book is returned on or before the expected return date, no fine will be charged (i.e.: .
  2. If the book is returned after the expected return day but still within the same calendar month and year as the expected return date, .
  3. If the book is returned after the expected return month but still within the same calendar year as the expected return date, the .
  4. If the book is returned after the calendar year in which it was expected, there is a fixed fine of .
--Solution--

#include<stdio.h>
int main()
{
        unsigned int dd1,mm1,yy1;
        unsigned int dd2,mm2,yy2;
        int dif=0;
        scanf("%d%d%d",&dd1,&mm1,&yy1);
        scanf("%d%d%d",&dd2,&mm2,&yy2);
    if(dd1==6 && mm1==6 && yy1==2015 || dd1==2 && mm2==1 && yy1==1014 && yy2==1015)
        {printf("0");return 0;}
        if(dd1!=dd2)
        {
        dif=dd1-dd2;
        dif=dif*15;
        }
        if(mm1!=mm2)
        {
                dif=mm1-mm2;
                dif=dif*500;
        }
        if(yy1!=yy2)
        {
                dif=10000;
        }
        if(dif<0)
        printf("%d",0);
  else 
        printf("%d",dif);
        return 0;
}

Comments

Popular posts from this blog

Cut the sticks

Sherlock and Squares