Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write c/c++ a program that requests the user to enter an alphabetic character. T

ID: 3799343 • Letter: W

Question

Write c/c++ a program that requests the user to enter an alphabetic character. Then convert the character from upper case to lower case or lower case to upper case. Print an error message if the user enters something other than an alphabetic character.

For example:

Enter an alphabetic character: A

Your input A converted to lower case is : a

Enter an alphabetic character: t

Your input t converted to upper case is T.

Enter a single digit or an alphabetic character: 9

You entered 9, which is not a letter.

Explanation / Answer

//C++ code
#include <iostream>
#include <random>
#include <string>
#include <iomanip>
#include <ctype.h>

using namespace std;

using namespace std;
int main()
{
char ch;
cout <<"Enter an alphabetic character :";
cin >> ch;

if(ch>='a' && ch<='z')
cout << "Your input " << ch << " converted to uppercase is : "<< char(toupper(ch)) << endl;

else if(ch>='A' && ch<='Z')
cout << "Your input " << ch << " converted to lowercase is : "<< char(tolower(ch)) << endl;
  
else
cout << "You entered " << ch << " which is not a letter. ";

return 0;
}


/*
output:

Enter an alphabetic character :A
Your input A converted to lowercase is : a

Enter an alphabetic character :C
Your input C converted to lowercase is : c

Enter an alphabetic character :9
You entered 9 which is not a letter.

Enter an alphabetic character :v
Your input v converted to uppercase is : V


*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote