Uppercase char to lowercase char issues

Hi all, below I've pasted a portion of code from a project I am working on. Regardless of what the user enters, I need the char to stay lowercase in the programs eyes because I am using //if (word.find(guess) != string::npos)// later on in my program (hangman game). This function only works with lowercase chars. If you run the program, the output is strange. I'm not sure why the char I'm trying to convert won't stay lowercase.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*Caleb Fischer
CSC 161--001
Project: 
Description*/
#include<iostream>

using namespace std; 

char letterValidation(char);

int main()
{
	char guess;

	cout << "Please enter a letter to guess." << endl;
	cin >> guess; 
	letterValidation(guess);
	cout << guess; 


	cout << "\n\n";
	system("pause"); 
	return 0; 
}

char letterValidation(char guess){

	if (isupper(guess))
	{
		putchar(tolower(guess));
	}
	else
	{
		/*Do nothing*/
	}
	return(guess);

}


EDIT: Wow, such a simple solution. I guess I love over complicating things! :) Thanks wildblue!
Last edited on
putchar prints out the lower case character but it doesn't save the value back to the guess variable.

Also guess is passed by value, so the original value back in main won't get changed. If you pass by reference and save the value of tolower(guess) back to the variable guess, I think you'll get the result you want.
Topic archived. No new replies allowed.