r/Cplusplus • u/Born_Juggernaut_346 • 4d ago
Discussion hi, i started learning cpp by myself since about 2 weeks ago, and i wrote my first useful simple program. the thing is that cause i learn by myself i don't know where my level is, so i wrote this program as a hope someone can judge me based on the simple first program i wrote.
/r/learnprogramming/comments/1y6p8u1/hi_i_started_learning_cpp_by_myself_since_about_2/
0
Upvotes
2
u/AKostur Professional 3d ago edited 3d ago
Not an unreasonable start. A few things to consider:
Getting a little more advanced:
7. Learn about iterators and ranges. The loop looking at users becomes (assuming that usernames should be unique):
auto it = std::ranges::find(users, iusername, &user::username);if ((it != users.end()) and (ipassword == it->password)) {doFoundUserThings(*it);return EXIT_SUCCESS;}Don't need the found or foundPoints variables anymore either.
Edit: Whups... std::ranges::find, not std::find.
2
u/Discordbothost 3d ago
Try saving two players with different scores, closing the program, and checking that each gets the same score after reopening it. Then test an unknown name. That gives you a small way to tell if the file round trip works while you split the code up. I'd use dummy data and drop the password part for this exercise.
2
u/FemaleMishap 3d ago
This is an afternoon of learning, not two weeks. Cross posting here was totally unnecessary.
1
u/CAPTAINCAPSLOCK111 2d ago
One useful next test: save the same Username and password twice, but give them different Points the second time. Your program appends both records, then the login loop stops at the first match, so you'll still get the old Points.
Decide, what you want duplicate - usernames to mean. For now, rejecting an existing username would be simpler than implementing updates. Load the users before saving the new one, And then check whether the name already exists, and only append if it doesn't.
Also check, whether the output file opened and whether writing succeeded. Right now.
addUser. -gives the caller no way to know that saving failed. Those two changes would teach you quite a bit about handling real program behaviour without needing to redesign everything.1
u/FckXFckMusk 13h ago
How do I block this sub now?