Error Check Help for lower case and upper case strings. Hello, I am using getlin
ID: 3758476 • Letter: E
Question
Error Check Help for lower case and upper case strings.
Hello, I am using getlines for someone to enter a name. The code then finds the character after the space and uses the value of the that 'char' to sort the names alphabetically.
it looks something like this to sort the name:
getline(cin, first_Last);
space_Location = first_Last.find(" ",0)
first = first_Last.subtr(0, space_Location);
last = first_Last.substr(space_Location+1);
I would like for my program to be error handled to where someone could enter "JOHN PENA" or "john pena" and assign the correct value for the 'P' in pena. I have looked online and found that using math to subtract ASCII values maybe an option. Is there something else that would make my code for effecient?
Explanation / Answer
you can give a check (without using ASCII)
if(last[0] >= 'A' &&last[0] <= 'Z')
last[0] = 'J';
else if(last[0] >= 'a' &&last[0] <= 'z')
last[0] = 'j';
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.