Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- void clr();
- void pause();
- int main()
- {
- //DECLARE THE VARIABLES FIRST
- int loginattempt;
- int rateperDay = 50;
- bool canLog = false;
- int allowedUsers[]={0, 1, 2, 3, 4};
- bool eng=false,math=true,fil=false;
- int mathDate[4] = {0,0,0,0};
- int engDate[3] = {0,0,0};
- int filDate[3] = {0,0,0};
- while(true){
- //TAKE AN INPUT FOR THE CLIENT'S STUDENT ID
- cout << "Please enter your student id:\t";
- cin >> loginattempt;
- //CHECK IF THE CLIENT IS ALLOWED FOR BORROWING BOOKS
- for(int i=0; i<=4; i++){
- if(allowedUsers[i]==loginattempt){
- canLog=true;
- }
- }
- clr(); //CLEAR THE OUTPUT
- while(canLog==true){
- int action;
- cout << "Welcome!\n";
- cout << "Please select an option:\n\n";
- cout << "\t1 -\tBorrow a book";
- cout << "\n\t2 -\tReturn a book";
- cout << "\n\nEnter an action:\t";
- cin >> action;
- clr();
- if(action==1){ // BORROW A BOOK
- int book;
- cout << "Enter the book you want to borrow(Note, Math book can be only borrowed once)";
- cout << "\n\n\t1 -\tMath";
- cout << "\n\t2 -\tEnglish";
- cout << "\n\t3 -\tFilipino";
- cout << "\n\nEnter a book:\t";
- cin >> book; clr();
- if(book==1){
- if(mathDate[3]==0){
- cout << "When are you going to return the book?\n\n";
- cout << "Please follow the example format for typing the date:\n\n";
- cout << "\tMonth: 8\n\tDay:12\n\tYear:20\n\n";
- cout << "Month: ";
- cin >> mathDate[0];
- cout << "Day: ";
- cin >> mathDate[1];
- cout << "Year: ";
- cin >> mathDate[2];
- mathDate[3]=1;
- math=true;
- clr();
- cout << "You have successfully borrowed Math\n";
- pause();
- clr();
- }else{
- cout << "Sorry, but this book is already borrowed once and can't be borrowed again.";
- pause();
- clr();
- }
- }else if(book==2){
- cout << "When are you going to return the book?\n\n";
- cout << "Please follow the example format for typing the date:\n\n";
- cout << "\tMonth: 8\n\tDay:12\n\tYear:20\n\n";
- cout << "Month: ";
- cin >> engDate[0];
- cout << "Day: ";
- cin >> engDate[1];
- cout << "Year: ";
- cin >> engDate[2];
- eng=true;
- clr();
- cout << "You have successfully borrowed English\n";
- pause();
- clr();
- }else if(book==3){
- cout << "When are you going to return the book?\n\n";
- cout << "Please follow the example format for typing the date:\n\n";
- cout << "\tMonth: 8\n\tDay:12\n\tYear:20\n\n";
- cout << "Month: ";
- cin >> filDate[0];
- cout << "Day: ";
- cin >> filDate[1];
- cout << "Year: ";
- cin >> filDate[2];
- fil=true;
- clr();
- cout << "You have successfully borrowed Filipino\n";
- pause();
- clr();
- }
- }else if(action==2){ //RETURN A BOOK
- int book;
- int overduePay=0;
- int cm, cd, cy;
- cout << "Please log the today's date(for simulation purposes only):\n\n";
- cout << "Please follow the example format for typing the date:\n\n";
- cout << "\tMonth: 8\n\tDay:12\n\tYear:20\n\n";
- cout << "Month: ";
- cin >> cm;
- cout << "Day: ";
- cin >> cd;
- cout << "Year: ";
- cin >> cy;
- clr();
- cout << "Please choose a book you're going to return";
- cout << "\n\n\t1 -\tExit";
- cout << "\n\t2 -\tMath";
- cout << "\n\t3 -\tEnglish";
- cout << "\n\t4 -\tFilipino";
- cout << "\n\nEnter a book:\t";
- cin >> book;
- clr();
- if(book==1){
- clr();
- }else if(book==2){
- if(math==true){
- if(cy!=mathDate[2] && mathDate[2]<=cy){
- overduePay += ((cy-mathDate[2])*rateperDay)*365; //365 days in a year
- }
- if(cd!=mathDate[1] && mathDate[1]<=cd){
- overduePay += ((cd-mathDate[1])*rateperDay);
- }
- if(cm!=mathDate[0] && mathDate[0]<=cm){
- overduePay += ((cm-mathDate[0])*rateperDay)*30; //30 days in a month
- }
- cout << "You're supposed to return Math at "<<mathDate[0]<<"/"<<mathDate[1]<<"/"<<mathDate[2]<<".";
- cout << "\nYou're returning it now at "<<cm<<"/"<<cd<<"/"<<cy<<".";
- if(overduePay==0){
- cout << "\nSuccessfully returned Math book!\n\n";
- pause();
- clr();
- }else{
- cout << "\n\nYou returned your book late\nPlease pay " << overduePay << " pesos to the counter.\n\n";
- pause();
- cout << "\n\nSuccessfully paid and returned Math book!\n\n";
- pause();
- clr();
- }
- }else{
- cout << "You haven't borrowed this book yet.\n";
- pause();
- clr();
- }
- }else if(book==3){
- if(eng==true){
- if(cy!=engDate[2] && engDate[2]<=cy){
- overduePay += ((cy-engDate[2])*rateperDay)*365; //365 days in a year
- }
- if(cd!=engDate[1] && engDate[1]<=cd){
- overduePay += ((cd-engDate[1])*rateperDay);
- }
- if(cm!=engDate[0] && engDate[0]<=cm){
- overduePay += ((cm-engDate[0])*rateperDay)*30; //30 days in a month
- }
- cout << "You're supposed to return English at "<<engDate[0]<<"/"<<engDate[1]<<"/"<<engDate[2]<<".";
- cout << "\nYou're returning it now at "<<cm<<"/"<<cd<<"/"<<cy<<".";
- if(overduePay==0){
- cout << "\nSuccessfully returned English book!\n\n";
- pause();
- clr();
- }else{
- cout << "\n\nYou returned your book late\nPlease pay " << overduePay << " pesos to the counter.\n\n";
- pause();
- cout << "\n\nSuccessfully paid and returned English book!\n\n";
- pause();
- clr();
- }
- }else{
- cout << "You haven't borrowed this book yet.\n";
- pause();
- clr();
- }
- }else if(book==4){
- if(fil==true){
- if(cy!=filDate[2] && filDate[2]<=cy){
- overduePay += ((cy-filDate[2])*rateperDay)*365; //365 days in a year
- }
- if(cd!=filDate[1] && filDate[1]<=cd){
- overduePay += ((cd-filDate[1])*rateperDay);
- }
- if(cm!=filDate[0] && filDate[0]<=cm){
- overduePay += ((cm-filDate[0])*rateperDay)*30; //30 days in a month
- }
- cout << "You're supposed to return Filipino at "<<filDate[0]<<"/"<<filDate[1]<<"/"<<filDate[2]<<".";
- cout << "\nYou're returning it now at "<<cm<<"/"<<cd<<"/"<<cy<<".";
- if(overduePay==0){
- cout << "\nSuccessfully returned Filipino book!\n\n";
- pause();
- clr();
- }else{
- cout << "\n\nYou returned your book late\nPlease pay " << overduePay << " pesos to the counter.\n\n";
- pause();
- cout << "\n\nSuccessfully paid and returned Filipino book!\n\n";
- pause();
- clr();
- }
- }else{
- cout << "You haven't borrowed this book yet.\n";
- pause();
- clr();
- }
- }
- }
- }
- }
- return 0;
- }
- void clr(){
- system("cls");
- }
- void pause(){
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement