r/programminghelp • • 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.

https://pastebin.com/WgFQSTHZ

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

22 comments sorted by

View all comments

Show parent comment

1

u/Creepy_Version_6779 Apr 16 '24

Using a class and function this time, I came up with this. Any advice is good even if I don't understand it yet, I can always come back to this.

2

u/DDDDarky Apr 16 '24

Seems ok, the only thing that worries me are your lines:

 myGame1.month = 04;

one of these days you are going to write something like

 myGame1.month = 09;

and wonder what happened

-> do not prefix your integers with 0.

1

u/Creepy_Version_6779 Apr 16 '24

roger, just fixed it. also changed it a bit using a constrictor this time. not too worried about the 0's being in the output atm :P https://pastebin.com/LJsCxTB6

2

u/DDDDarky Apr 16 '24

I don't see anything wrong with it, you could also add the other variables into the constructor.