Library Fines ,this program was created to solve Library Fines problem.
The fee structure is as follows:
- If the book is returned on before 5 days, no fine will be charged.
- If the book is returned after the expected return day (between 5 and 10 days) – fine: 0.5$ per day
- If the book is returned after the expected return day (between 10 and 30 days) fine: 1$ per day
- If the book is not returned after 30 days, cancel membership. fine: 1.5$ per day
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include<iostream> #include<stdlib.h> using namespace std; int main() { int days; float fine = 0; cout<< "Enter total days: "; cin>>days; if (days <= 5) { fine = 0; } else if (days > 5 && days <= 10) { fine = (days - 5) * 0.5F; } else if (days > 10 && days <= 30) { // ----5 days--- --between 10 and 30--- fine = 5 * 0.5F + (days - 10) * 1; } else { // -5 days- -10 , 30- - >30 - fine = 5 * 0.5F + 20 * 1 + (days - 30) * 1.5F; cout<<"Canceled your Membership"; } cout<<"Your fine:" << fine<<"$"; return 0; } |
This example was prepared to teach variable and comparison operations.
You can find more similar examples of programming for this programming language in the site.