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.
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?
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?
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()