Lowercase to Uppercase without ctype

I have the idea of doing it but where can I find letter values online? I searched everywhere!

This is my concept so far of doing so, I know that each letter has its initial value such as 'A' = 65 and that lowercase letters have higher values, so if I can find the value I can do 'a' - 'A' = temp, 'a' -= temp.

What do you guy think? Would that work?
Yea, it will work. What your looking for is a chart of ASCII characters, here is a link

http://www.melbpc.org.au/pcupdate/9100/9110article6-2.gif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
char toUpper( char a ); // If the passed character is a lower-case letter, returns the corresponding upper-case letter; else, returns the passed character unchanged.


int main()
{
  //toUpper
  cout << char('a') << endl;

  return 0;
}

char toUpper( char a )
{
  char(a - 32);
  return a;
}



I know this piece of code has major issues on why it ain't working lol, I am pretty new and not sure on how to start it, any tips on fixing it?

The output right now is just 'a'
1
2
3
4
5
6
7
char toUpper( char a )
{
	char a;
	char upperCase = 0;
    upperCase = a - 32;
    return upperCase;
}


I tried this as well, no luck
I can do 'a' - 'A' = temp, 'a' -= temp.
Yes, you can
1
2
3
4
int main(){
  int qty = 'z'-'a'+1;
  cout << qty << endl;
}

Your code makes no sense, please review http://cplusplus.com/doc/tutorial/functions/ (and next)
In general case it will not work for example if you use EBCDIIC
Sorry, I am kind of new to programming so a lot of which is confusing for me.

As for ne555,

I don't really get what your piece of code did, but what my assignment requires me to do is to use a function and a main, so how would I go about doing so?
see my comments:

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
char toUpper( char a );


int main()
{
  //toUpper
  cout << char('a') << endl;  // <- this line does not call 'toUpper', it just prints 'a'
      // if you want to call 'toUpper' you should do this:
//cout << toUpper('a') << endl;

  return 0;
}

char toUpper( char a )
{
  char(a - 32);  // <- this line does nothing.  it takes the a variable, subtracts 32, then
   // throws the result away.  If you want to actually modify a, you need to assign it.
   //  either with:
//a -= 32;
   // or...
//a = a - 32;

  // although, you should avoid magic numbers like 32.  It may not be immediately clear that
  // 32 is the ascii difference between upper and lowercase letters.  Instead, you should
  //  actually use ascii codes directly so there's no confusion.  This also means you don't
  //  have to memorize ascii codes:
//a = a + 'A' - 'a';  // add an uppercase letter, then subtract a lowercase letter = letter is uppercase
  return a;
}
Thanks Disch, I feel so stupid in the int main() lol

I am starting to get it a little bit, and I understand how I can turn a specific letter to upper case by subtracting it but how do I go about doing so with any letters when I do this in int main()

1
2
3
4
5
int main()
{
   cout << toUpper('g') << endl;

}
Disch's example should work for any letter since the difference between upper and lower case is the same in every case (At least for ASCII).
Topic archived. No new replies allowed.