Library Fine Calculation using C++ Programming


The program is written in C++ programming language and calculates the fine amount for late membership renewal based on the number of days a member has delayed the renewal.

The program starts by declaring a variable named "days" of integer data type. The user is then prompted to enter the number of days the membership has been delayed. The input value is stored in the variable "days" using the "cin" function.

The program then uses an if-else statement to check the value of the variable "days" and calculates the fine amount accordingly. If the value of "days" is between 1 and 5, the fine amount is 0.50 per day. If the value of "days" is between 6 and 10, the fine amount is 1 per day. If the value of "days" is between 11 and 30, the fine amount is 5 per day.

If the value of "days" is greater than 30, the program displays a message stating that the membership will be cancelled. Finally, the program returns 0, indicating successful execution.

Source Code

/*
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.
 
>0 <=5  /0.50
>=6 <=10  /1
>10 <=30 /5
>30
*/
 
#include<iostream>
using namespace std;
int main()
{
    int days;
    cout<<"Enter the number of days:";
    cin>>days;
    if(days>0 && days<=5)
    {
        cout<<"\nPer Day Fine Amount is : 0.50";
        cout<<"\nTotal Fine Amount is : "<<days*0.50;
    }
    else  if(days>=6 && days<=10)
    {
        cout<<"\nPer Day Fine Amount is : 1";
        cout<<"\nTotal Fine Amount is : "<<days*1;
    }
     else  if(days>10 && days<=30)
    {
        cout<<"\nPer Day Fine Amount is : 5";
        cout<<"\nTotal Fine Amount is : "<<days*5;
    }
    else
    {
        cout<<"\nmembership will be cancelled.";
    }
    return 0;
}
 

Output

Enter the number of days:6

Per Day Fine Amount is : 1
Total Fine Amount is : 6
To download raw file Click Here

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples