So I'm making a really simple rock paper scissors game in c++. I used to be able to convert my char variable to uppercase, but it did not allow me to add spaces to my username. I converted it to string and I have been searching back and forth how to change the string to uppercase as my one does not work :S - hopefully some of you can help...thanks!
You want the user name to be uppercase?
If so you have to pass the string name by reference.
void upcase(string & name); //calling upcase function
1 2 3 4 5 6 7
void upcase(string & name){ //defining the function
int length;
length = name.size(); //making length = to the length of the string (works fine)
int p;
for(p = 0; p < length; p++) {
name[p] = toupper(name[p]); //this SHOULD convert string name; to uppercase but it doesnt
}
Script Coder:
For me it says (I'm using codeblocks if that helps in any way)
undefined reference to std::string name
this is with the upcase(name); line with your code :S
and if I put upcase(string name) it says expected primary-expression before name
@khal: void upcase(string & name); that is not the `calling', just the prototype.
@OP: the prototype and definition must match.
If you are planning to use Script Coder's version, then the calling should be upcase( &name ); as the function ask for a pointer