Library program in C


A library charges a fine for every book returned late. For first 5 days the fine is 50 paise per day, for 6-10 days fine is one rupee per day and above 10 days fine is 5 rupees per day. If you return the book after 30 days your membership will be cancelled. Write a program in C to accept the number of days the member is late to return the book and display the fine or the appropriate message.
            #include <stdio.h>
            #include <conio.h>
            void main()
            {
                        int days;
                        float fine;
                        clrscr();
                        printf("Enter the number of days : ");
                        scanf("%d", &days);
                        if(days <= 5) {
                                    fine=days*.5;
                                    printf("\nFine : Rs.%.2f", fine);
                        } else if (days>5 && days<=10) {
                                    days=days-5;
                                    fine=days*1;
                                    fine=fine+2.5; //Rs.2.5 is fine for first 5 days
                                    printf("\nFine : Rs.%.2f", fine);
                        } else if (days>10 && days<=30) {
                                    days=days-10;
                                    fine=days*5;
                                    fine=fine+7.5; //Rs.7.5 is fine for last 10 days
                                    printf("\nFine : Rs.%.2f", fine);
                        } else {
                                    printf("\nYour membership has been cancelled");
                        }
                        getch();
            }


Post a Comment