r/programminghelp • u/Creepy_Version_6779 • Apr 13 '24
C++ Having trouble stringing 3 integers from a struct. C++ Beginner
I'm very new and just decided to change the integers into strings.
The integers in mind were the month day year values.
month, day, and year were changed from int to string to get the code to run. maybe im right to have them as strings? idk, is there a way to do this with integers?
0
Upvotes
View all comments
Show parent comment
2
u/DDDDarky Apr 14 '24 edited Apr 14 '24
Yes, that is what you get for this specific day-month configuration.
If you are happy with that, that's all good, although you have just written code looking like this. That is of course assuming your configuration of dates is fixed.
I'm trying to point out there may be other configurations other than this one where you might get unwanted results, such as this.
Therefore, you could use the format string I have suggested few comments back to get a result like this.
I hope I am not throwing too advanced concepts at you, but you might notice there is now duplicated code (the format is basically copy-pasted with different arguments), so it could use some refactoring, for example by creating a member function that creates the formatted string, like this.
And maybe if you want to feel even more fancy you could use a container like std::vector to add all your games into, so that you can just iterate them instead of copy-pasting the printing for each one, you could end up with something like this.
(Note this is all just a suggestion what you could do, not what you have to do, I don't know what are your requirements of the code, or if these topics are too advanced)