First off, I'm new here, so, I would like to say Hi : P
My name is Zach, and I am relatively new to coding. I have been taking an online course for the past few days to teach me a strong amount of knowlege in video game design and developement, but I had previously known some of the basics of C++. (The course is over 8 months, so i will be learning everything from the basics of coding up to a ton of different stuff, so it's ok that i lack this much knowledge when im taking this course.)
My problem is in an exercise given to me at the end of the third chapter of my book. I am supposed to write a program that will prompt the user to enter a letter, and then output the letter in its opposite case (Upper/Lower) using functions. I'm fairly sure the code i have written will work, just as soon as i figure out this problem. I don't currently know how to fix it myself, so help would be appreciated.
The code is:
#include <iostream>
usingnamespace std;
char ToUpperCase ( char i ); //Declaring the functions so they can be called by the code.
char ToLowerCase ( char i );
int main ()
{
char input; //Creating the variable for the letter.
cout << "Enter a letter to have it's 'case' changed: ";
cin >> input; //Setting the variable.
cout << endl;
int I = input; //Converting the letter into a distinguishable integer through a different variable.
if ( 65 <= I, I <= 90) //Checking the integer form of the letter to choose which case to change to.
{
cout << ToLowerCase (input) << endl; //Sends the letter to the function.
}
elseif ( 97 <= I, I <= 122 ) //Same notes as the "if"
{
cout << ToUpperCase (input) << endl;
}
else
{
cout << "You have input an invalid character, please enter a letter (A-Z).";
cin >> input;
} //Prompts the user to re enter a character. I believe I will need to add more code to this section later.
} //I will know after I can test the entire program.
char ToLowerCase ( char i ) //Function that changes an Upper case letter to a Lower case letter.
{
int x = i; //Converts letter into an integer.
int I = 32 + x; //Converts letter value to its opposite case's value.
char output = I; //Converts letter value of opposite case back to a character.
return output; //Returns the actual character.
}
char ToUppercase ( char i )
{
int x = i;
int I = x - 32;
char output = I;
return output;
} //Same notes as previous function.