Include stdio.h to use it. But don't focus on it now. Focus on getting your cout and precision to work instead.
This is a discussion on Need help on Reading from a file within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by lifeis2evil I've never seen sprintf befores >_< http://msdn2.microsoft.com/en-us/lib...1k(VS.80).aspx Include stdio.h to use it. But don't focus on ...
No, I think that's alright. So have you tested it yet?
>> I am sure I have it in the wrong spot, should it be in the if / else ?
I would put it immediately before the cout call that needs to be affected by the maipulators. In this case, those cout calls are inside the if/else if. It can work where you have it if you fix the one small error you have left, but it might make more sense to the reader (and you) to keep it close to the place that is affected.
Seeing as there's only one call to cout and two IFs, I don't see why you can't put it before the IFs, where it's right now. It shouldn't hurt.
It shouldn't hurt, I just think it makes more sense (especially from a novice programmer's point of view) to put it next to the places in the code that use.
Alright, good grief. Good work.
Now you can experiment with sprintf_s is you want Or you could just go to bed and get some sleep! Like me!
The last thing you should do is fix up your indentation a bit. It will make it easier for the grader to read the program, and easier for you and others to go back and see what's going on. Plus, it's a good habit to get into (although really the indentation should be kept properly from the beginning).
haha I definitely neeeed sleep or else I think I could possibly pass out lol ..well not really my eyes just hurt and are watery and I still have to do the chart thing but I'll do it tomorrow morning cause I think I have all day tomorrow to submit hopefully
I like the first better. It makes it clearer when you've forgotten or decided not to initialize a variable.
In general, though, it is better to declare variables only when you are ready to use them. That would mean many of those variables would be declared lower in the code. In your case, however, it is not worth it for you to try and make that change to this assignment.
>> show_gender = '\0'
That just initializes show_gender to the null character. \0 is an escape sequence. It just represents a character that can't be displayed normally.
Since initializing variables is always good practice, Elysia just picked a character to initialize with. Any character will work, but the null character is the default value for a char so it might make more sense. It turns out in this case that it doesn't matter what it is, the code will execute the same regardless. You could even leave it uninitialized, since the first time it is used it will be given a value.