On my Ubuntu machine, this code works fine. But when I compile and run it on Windows, I get different output and it keeps looping at getgender().
Please Enter your Name: My Name
Male / Female[m/f]: m
Gender in getgender() is: m
Gender in Main block is: ╕
Male / Female[m/f]: f
Gender in getgender() is: f
Gender in Main block is: ╕
Male / Female[m/f]:
Try to directly change "gender" in main by
getgender(string, char&); //put gender as the second parameter, and in getgender to assign the result directly to the reference.
Thanks for the reply. I am yet to get to pointers and references so can you please give example of how to put gender as the second parameter.
I was taught functions so I decided to create a program using it.
I enabled warnings on my linux box using -Wall compiler flag and got this message:
1 2
chartest.cpp: In function ‘char getgender(std::string)’:
chartest.cpp:54: warning: control reaches end of non-void function
so I added return 0 after the else statement and it works well now.
I will try on how to change gender and see what will happen when I get to pointers.