How do I use a call-by-reference char??

I don't know how to use a char in a function where I call it by reference.

Here is my code. The idea is converting 24hr to 12hr time.

int twelvehour(int hours, int minutes, char& aorp, char& colon) {

if((hours > 12) | (hours = 0)) {
hours = fabs(hours -12);
aorp = "P";
} else {
aorp = "A";
}

if(minutes < 10) {
colon = ":0";
} else {
colon = ":";
}
}
| should be ||, even though I don't think it can do any harm.
fabs doesn't do what you want it to do. Your code will convert 9 to 3 and 17 to 5. You should instead use %12.
Also, you should pass hours and minutes by reference too. And why return an int?
"P" and "A" and ":0" and ":" are not characters, but strings.
One option would be to pass aorp and colon as std::strings or char arrays (of course they'd have to be that in the main program too), another would be not to pass aorp and colon at all. You can use std::stringstream or sprintf to combine hours, minutes and :s and return the whole string.
Topic archived. No new replies allowed.