Saturday, January 30, 2010

CHAP 2[F]e Library fine

A library charges a fine for every book returned late. For first 5 days the fine is 50 paise, for 6-10 days fine is one rupee and above 10 days fine is 5 rupees. If you return the book after 30 days your membership will be cancelled. Write a program to accept the number of days the member is late to return the book and display the fine or the appropriate message.


void main()
{
float fine;
int d;
printf("\nInput the number of days overdue");
scanf("%d",&d);

if(d<=5)
printf("\nThe fine is %f",fine=1.0*d);

else if(d>5&&d<=10)
printf("\nThe fine is%f",fine=(1.0*5)+(2.0*(d-5)));

else if(d>10&&d<30)
printf("\nThe fine is %f",fine=(1.0*5)+(2*5)+3*(d-10));

else if(d>=30)
printf("\nMembership cancelled and a fine of %f imposed",fine=(1.0*5)+(2.0*5)+3*(d-10));
}

1 comment:

  1. fine 50 paise so
    when d<=5
    printf(fine is %f,fine=0.5*d);
    all three conditions are not correct according to question

    ReplyDelete