Converting lower to upper

Hello, I'm trying to have a function outside of main check to see if a number is lowercase, and then to make it uppercase if it is. So far I have this but I'm showing errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool Upper(char x)
{
	if (islower(x))
		putchar (toupper(x));
	return x;
}

int _tmain(int argc, _TCHAR* argv[])
{
	char x;
	int y;
	cout << "Please press a key" << endl;
	cin >> x;
	Upper(x);
	cout << Upper(x);


errors are

1>(34): error C2084: function 'bool Upper(char)' already has a body
1>(17) : see previous definition of 'Upper'
1>(46): error C3861: 'Upper': identifier not found
1>(47): error C2568: '<<' : unable to resolve function overload
1>(17): could be 'bool Upper(char)'
1>(47): error C3861: 'Upper': identifier not found
I would suggest using ASCII values... If it's between certain values it would be either uppercase or lowercase.

- Kyle
It says you've defined your Upper function at more than 1 location.
Can you post what's at line 17 of your cpp file ?
Ok I made changes on lines 30-35. I had two instances of Upper. I also was putchar instead of return.

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
39
40
41
42
43
44
45
46
47
#include "stdafx.h"
#include "iostream"
#include "ctype.h"
using namespace std;

bool Digit(char x)
{	
	if (isdigit(x))
		return 1;
	else 
		return 0;
}

bool Upper(char x)
{
	if (isupper(x))
		return 1;
	else 
		return 0;
}

bool Lower(char x)
{
	if (islower(x))
		return 1;
	else 
		return 0;
}

char Change(char x)
{
	if (islower(x))
	return (toupper(x));
	else 
	return x;
}

int _tmain(int argc, _TCHAR* argv[])
{
	char x;
	int y;
	cout << "Please press a key" << endl;
	cin >> x;
	Change(x);
	cout << Change(x);
}
Last edited on
Topic archived. No new replies allowed.