❔ Hello guys, I'm just trying to create two functionalities which's borrow and return books.

BlazeBin - amnpmjcagrtk
A tool for sharing your source code with the world!
36 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
The king of kings
Hello there I hope you could help me out with this project 🤗 Are you available?
Timtier
Timtier2y ago
What are you having problems with?
The king of kings
Thanks a lot for showing up 🙂 I've been stuck with this project for a weeks. Since I'm a beginner and trying to practice my code skills. I'm building this project where I could enable the user to borrow & return books. The issue is every time I enter a book title it displays
Console.WriteLine("Please enter a valid book! ");
Console.WriteLine("Please enter a valid book! ");
My goal is that when the user types the title of the book it should borrow by removing the book from libraryBooks and adding it to the MyBooks list. And the opposite when returning the book I am bad at coding and I would love to learn how to code, but a project like this seems hard for me to code a lone by my self 🤷🏻‍♂️
blinkbat
blinkbat2y ago
start simpler. can you make a console app that does simple math calculations with two numbers and an operator? if not, can you make one that takes the user's name input and puts it into a sentence?
The king of kings
Well! These stuff are very simple, I've been doing the a lot through tutorials. But my project, I think is too advanced for me too.
Timtier
Timtier2y ago
You can always try to define what you're doing in smaller, more manageable or easier to understand steps 🙂
The king of kings
I've heard this not once but hundreds of times and this are what I'm trying to do.
Timtier
Timtier2y ago
But if you want we can have a look at the specific issue you're encountering
The king of kings
For example! If I would apply this to my example, how am I going to do this in small steps? Can you provide me with some hints? Sounds great 😃
Timtier
Timtier2y ago
For small steps I would mean more the full program or chunks of it, but we can get back to that later 🙂
The king of kings
I would love to learn how to code and very excited, but when I get stuck, it just feels boring and not know what to do or what step should I take.
Timtier
Timtier2y ago
So my first hint would be here; find where you have the Please enter a valid book! in your code so you know at what piece of code you likely have to look. Plus, does this only happen when borrowing a book, when you return it, or both?
The king of kings
You're right. My first issue is in this code
The king of kings
Not really sure where the issue is, but this code gets printed when I type a book title
"Please enter a valid book! "
"Please enter a valid book! "
Timtier
Timtier2y ago
Even when you enter the correct title?
The king of kings
Yep
ero
ero2y ago
Especially when they enter a correct title. The condition is wrong It's saying the title is invalid when it does exist
The king of kings
Oh! Really. It was some guy who wrote this project for me, I'm not sure if got it right 🤔
Timtier
Timtier2y ago
Hope you didn't pay 😛
ero
ero2y ago
I mean why do we have to riddle this for you? Literally look at the code, it's self explanatory
while Exists is true, print Book Invalid
The king of kings
No, it's just a guy I met who studies computer science, who usually calls me and teaches me how to build projects and explains every line of code.
Timtier
Timtier2y ago
They've specifically said they're a beginner. But I'd agree to start a bit simpler to get more knowledge of the concepts that are used here If you are getting used to it, or are trying to your own program, it's beneficial to write it in pseudocode like the example from Ero before you try to "make it work". It's a bit easier to write down something along of the lines of
if I want to borrow a book and the library has it, I can borrow it.

if I want to borrow a book and the library does not have it, I can't borrow it
if I want to borrow a book and the library has it, I can borrow it.

if I want to borrow a book and the library does not have it, I can't borrow it
The king of kings
You're right. It looks exactly as you described. But I don't know what this line of code exactly means!
(x => x.Title == title)
(x => x.Title == title)
Timtier
Timtier2y ago
That's a predicate, or shortly put; Given item x from the collection of library books, it checks if the Title of Book x is the same as the title variable.
ero
ero2y ago
MyBooks is a collection. Exists "walks" that collection, and does a check for every element it finds. for every element it finds, it executes the function x => x.Title == title where x is the current element to check using x in predicates is very bad practice that way too many people do MyBooks.Exists(book => book.Title == title)
The king of kings
Ok! Wow, that's a whole amount of rewarding information and tips regarding my project. I learned a lot of things from you guys that I had no idea about it. This is what confused most are these x stuff. So is Exists used as a method in this case and not only a word?
Timtier
Timtier2y ago
Yep, it is a method that belongs to a List
The king of kings
Ok! Now, I understood almost the whole idea. Let me practice by modifying the code and see if I get it right.
Timtier
Timtier2y ago
Good luck!
The king of kings
Thank you so much 🤗 Can I show you my updated project so you can just review it later?
Timtier
Timtier2y ago
Sure, how strict do you want me to be? 😛
The king of kings
You decide 😁
The king of kings
Guys, yesterday, I found out that it was me who changed it from false to true, so it was my fault 😆
while (MyBooks.Exists(book => book.Title == title) is false)
while (MyBooks.Exists(book => book.Title == title) is false)
https://paste.mod.gg/nhpayuykleaz/2
BlazeBin - nhpayuykleaz
A tool for sharing your source code with the world!
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.