The whole point of the homework is to test an overloaded constructor. If I manually put an int into the constructor it works and I get the correct result BUT I cannot figure out how to get it to take a set of 3 characters like "jun" or "dec".

If I leave the constructor empty, it runs the default constructor like it should.
If I put in a "2", February comes out like it should.
But if I put in "jan" or any other set of 3 characters I get a blank.

If I leave the constructor empty, it runs the default constructor like it should.

That's good. :)

Quote:

If I put in a "2", February comes out like it should.

Really? Because "2" is a string. It shouldn't work, if in fact you mean "2" and not the number.

Quote:

But if I put in "jan" or any other set of 3 characters I get a blank.

I think this is related to my earlier comment. 'jan' isn't a string either. It's a multibyte character constant. Compilers usually warn when you are using one that does not exist. Are your warnings turned on to the highest level? It really helps. Unfortunately you need to fix this everywhere now though.

There is another problem with months argument before this can work. The parameter should be changed to char * (and compared with strcmp), or since this is C++, just use std::string. String always saves a bunch of headaches.

10-05-2010

DHart07

I would love to use a string...but those aren't covered until next chapter :( so that still kind of leaves me in the dark. I was originally trying to take input from the console, but that just further complicated things and since I don't HAVE TO read from the console I figured just manually entering the info would be easier. I understand where the disconnect is and why it doesn't properly function, I just don't really know where to go from here.

If you can't do that for some reason, that's OK, just don't make a class that can build off of a string like you've been trying. Use the numbers.

10-05-2010

DHart07

If I were to use the strcmp what would my syntax be for the input in the constructor? And why are they all == 0? I don't follow the logic.

The assignment is to have an overloaded constructor that takes the month by either int or 3 char am I totally missing the point behind this then?

10-05-2010

whiteflags

Quote:

The assignment is to have an overloaded constructor that takes the month by either int or 3 char am I totally missing the point behind this then?

I highly doubt I'm wrong. 3 char if you take that literally is just a multicharacter constant. And you know that doesn't work. 3 char if you interpret it to mean "use a string" then it at least makes sense.

Quote:

If I were to use the strcmp what would my syntax be for the input in the constructor? And why are they all == 0? I don't follow the logic.

strcmp is just a function, not attached to any class or anything. You'd call it like any other function, but you have to know what it returns and why to understand how it works. Sorry, I didn't explain that. I was hoping you'd go and research that, I guess. No problemo though.

I really don't know what else to tell you, though.

10-05-2010

DHart07

Well on a positive note, what you suggested works. I understand the syntax now that it worked, before I must have typoed something because it didn't work and it left me lost. The homework isn't due for a few days so I'll present it to the professor and if he doesn't like how I did it I'll just see how he wants it. Thanks for the help man, I appreciate it.

10-06-2010

Elysia

You really should make those functions accept const char* instead of char* because you are not going to modify them (const correctness).