Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. void clr();
  6. void pause();
  7.  
  8. int main()
  9. {
  10. //DECLARE THE VARIABLES FIRST
  11. int loginattempt;
  12. int rateperDay = 50;
  13. bool canLog = false;
  14. int allowedUsers[]={0, 1, 2, 3, 4};
  15. bool eng=false,math=true,fil=false;
  16. int mathDate[4] = {0,0,0,0};
  17. int engDate[3] = {0,0,0};
  18. int filDate[3] = {0,0,0};
  19.  
  20. while(true){
  21. //TAKE AN INPUT FOR THE CLIENT'S STUDENT ID
  22. cout << "Please enter your student id:\t";
  23. cin >> loginattempt;
  24.  
  25. //CHECK IF THE CLIENT IS ALLOWED FOR BORROWING BOOKS
  26. for(int i=0; i<=4; i++){
  27. if(allowedUsers[i]==loginattempt){
  28. canLog=true;
  29. }
  30. }
  31.  
  32. clr(); //CLEAR THE OUTPUT
  33.  
  34.  
  35. while(canLog==true){
  36. int action;
  37. cout << "Welcome!\n";
  38. cout << "Please select an option:\n\n";
  39. cout << "\t1 -\tBorrow a book";
  40. cout << "\n\t2 -\tReturn a book";
  41. cout << "\n\nEnter an action:\t";
  42. cin >> action;
  43. clr();
  44. if(action==1){ // BORROW A BOOK
  45. int book;
  46. cout << "Enter the book you want to borrow(Note, Math book can be only borrowed once)";
  47. cout << "\n\n\t1 -\tMath";
  48. cout << "\n\t2 -\tEnglish";
  49. cout << "\n\t3 -\tFilipino";
  50. cout << "\n\nEnter a book:\t";
  51. cin >> book; clr();
  52. if(book==1){
  53. if(mathDate[3]==0){
  54. cout << "When are you going to return the book?\n\n";
  55. cout << "Please follow the example format for typing the date:\n\n";
  56. cout << "\tMonth: 8\n\tDay:12\n\tYear:20\n\n";
  57. cout << "Month: ";
  58. cin >> mathDate[0];
  59. cout << "Day: ";
  60. cin >> mathDate[1];
  61. cout << "Year: ";
  62. cin >> mathDate[2];
  63. mathDate[3]=1;
  64. math=true;
  65. clr();
  66. cout << "You have successfully borrowed Math\n";
  67. pause();
  68. clr();
  69. }else{
  70. cout << "Sorry, but this book is already borrowed once and can't be borrowed again.";
  71. pause();
  72. clr();
  73. }
  74. }else if(book==2){
  75. cout << "When are you going to return the book?\n\n";
  76. cout << "Please follow the example format for typing the date:\n\n";
  77. cout << "\tMonth: 8\n\tDay:12\n\tYear:20\n\n";
  78. cout << "Month: ";
  79. cin >> engDate[0];
  80. cout << "Day: ";
  81. cin >> engDate[1];
  82. cout << "Year: ";
  83. cin >> engDate[2];
  84. eng=true;
  85. clr();
  86. cout << "You have successfully borrowed English\n";
  87. pause();
  88. clr();
  89. }else if(book==3){
  90. cout << "When are you going to return the book?\n\n";
  91. cout << "Please follow the example format for typing the date:\n\n";
  92. cout << "\tMonth: 8\n\tDay:12\n\tYear:20\n\n";
  93. cout << "Month: ";
  94. cin >> filDate[0];
  95. cout << "Day: ";
  96. cin >> filDate[1];
  97. cout << "Year: ";
  98. cin >> filDate[2];
  99. fil=true;
  100. clr();
  101. cout << "You have successfully borrowed Filipino\n";
  102. pause();
  103. clr();
  104. }
  105. }else if(action==2){ //RETURN A BOOK
  106. int book;
  107. int overduePay=0;
  108. int cm, cd, cy;
  109. cout << "Please log the today's date(for simulation purposes only):\n\n";
  110. cout << "Please follow the example format for typing the date:\n\n";
  111. cout << "\tMonth: 8\n\tDay:12\n\tYear:20\n\n";
  112. cout << "Month: ";
  113. cin >> cm;
  114. cout << "Day: ";
  115. cin >> cd;
  116. cout << "Year: ";
  117. cin >> cy;
  118. clr();
  119. cout << "Please choose a book you're going to return";
  120. cout << "\n\n\t1 -\tExit";
  121. cout << "\n\t2 -\tMath";
  122. cout << "\n\t3 -\tEnglish";
  123. cout << "\n\t4 -\tFilipino";
  124. cout << "\n\nEnter a book:\t";
  125. cin >> book;
  126. clr();
  127. if(book==1){
  128. clr();
  129. }else if(book==2){
  130. if(math==true){
  131. if(cy!=mathDate[2] && mathDate[2]<=cy){
  132. overduePay += ((cy-mathDate[2])*rateperDay)*365; //365 days in a year
  133. }
  134. if(cd!=mathDate[1] && mathDate[1]<=cd){
  135. overduePay += ((cd-mathDate[1])*rateperDay);
  136. }
  137. if(cm!=mathDate[0] && mathDate[0]<=cm){
  138. overduePay += ((cm-mathDate[0])*rateperDay)*30; //30 days in a month
  139. }
  140. cout << "You're supposed to return Math at "<<mathDate[0]<<"/"<<mathDate[1]<<"/"<<mathDate[2]<<".";
  141. cout << "\nYou're returning it now at "<<cm<<"/"<<cd<<"/"<<cy<<".";
  142. if(overduePay==0){
  143. cout << "\nSuccessfully returned Math book!\n\n";
  144. pause();
  145. clr();
  146. }else{
  147. cout << "\n\nYou returned your book late\nPlease pay " << overduePay << " pesos to the counter.\n\n";
  148. pause();
  149. cout << "\n\nSuccessfully paid and returned Math book!\n\n";
  150. pause();
  151. clr();
  152. }
  153.  
  154. }else{
  155. cout << "You haven't borrowed this book yet.\n";
  156. pause();
  157. clr();
  158. }
  159.  
  160. }else if(book==3){
  161. if(eng==true){
  162. if(cy!=engDate[2] && engDate[2]<=cy){
  163. overduePay += ((cy-engDate[2])*rateperDay)*365; //365 days in a year
  164. }
  165. if(cd!=engDate[1] && engDate[1]<=cd){
  166. overduePay += ((cd-engDate[1])*rateperDay);
  167. }
  168. if(cm!=engDate[0] && engDate[0]<=cm){
  169. overduePay += ((cm-engDate[0])*rateperDay)*30; //30 days in a month
  170. }
  171. cout << "You're supposed to return English at "<<engDate[0]<<"/"<<engDate[1]<<"/"<<engDate[2]<<".";
  172. cout << "\nYou're returning it now at "<<cm<<"/"<<cd<<"/"<<cy<<".";
  173. if(overduePay==0){
  174. cout << "\nSuccessfully returned English book!\n\n";
  175. pause();
  176. clr();
  177. }else{
  178. cout << "\n\nYou returned your book late\nPlease pay " << overduePay << " pesos to the counter.\n\n";
  179. pause();
  180. cout << "\n\nSuccessfully paid and returned English book!\n\n";
  181. pause();
  182. clr();
  183. }
  184.  
  185. }else{
  186. cout << "You haven't borrowed this book yet.\n";
  187. pause();
  188. clr();
  189. }
  190. }else if(book==4){
  191. if(fil==true){
  192. if(cy!=filDate[2] && filDate[2]<=cy){
  193. overduePay += ((cy-filDate[2])*rateperDay)*365; //365 days in a year
  194. }
  195. if(cd!=filDate[1] && filDate[1]<=cd){
  196. overduePay += ((cd-filDate[1])*rateperDay);
  197. }
  198. if(cm!=filDate[0] && filDate[0]<=cm){
  199. overduePay += ((cm-filDate[0])*rateperDay)*30; //30 days in a month
  200. }
  201. cout << "You're supposed to return Filipino at "<<filDate[0]<<"/"<<filDate[1]<<"/"<<filDate[2]<<".";
  202. cout << "\nYou're returning it now at "<<cm<<"/"<<cd<<"/"<<cy<<".";
  203. if(overduePay==0){
  204. cout << "\nSuccessfully returned Filipino book!\n\n";
  205. pause();
  206. clr();
  207. }else{
  208. cout << "\n\nYou returned your book late\nPlease pay " << overduePay << " pesos to the counter.\n\n";
  209. pause();
  210. cout << "\n\nSuccessfully paid and returned Filipino book!\n\n";
  211. pause();
  212. clr();
  213. }
  214.  
  215. }else{
  216. cout << "You haven't borrowed this book yet.\n";
  217. pause();
  218. clr();
  219. }
  220. }
  221. }
  222. }
  223. }
  224.  
  225. return 0;
  226. }
  227.  
  228. void clr(){
  229. system("cls");
  230. }
  231. void pause(){
  232. system("pause");
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement