Problem 2 Write a program that converts lowercase alphabets to uppercase alphabe
ID: 3796959 • Letter: P
Question
Problem 2 Write a program that converts lowercase alphabets to uppercase alphabets. Your program shou prompt the user to enter a character. Ifthe user did not enter a valid character (i.e. a through z), you have to tell the user that the entry is incorrect. If the user entered a valid character, you'll have convert this user entered lowercase character to its corresponding uppercase character and display t result For example, if the user enters a, you'll have to display A. (10 point HINT: a. You will need a character variable, and ask the user for its value. b. You will have to check whether the entered character is a valid character or not. For that, you will have to check its ASCII value. Remember the characters a through z have a continuous ASCII values. c. ASCII values are integers. To convert to uppercase, you'll have to subtract something (think what) from the ASCII values. The uppercase alphabets have continuous ASCII values as well.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
char lower, upper;
cout<<"Enter the chracter: ";
cin >> lower;
if(lower >='a' && lower <= 'z'){
upper = lower - 32;
cout<<"Given lower letter "<<lower<<" and corresponding upper letter "<<upper<<endl;
}
else{
cout<<"Invaid entry. chracter must be between a and z."<<endl;
}
return 0;
}
OUtput:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the chracter: a
Given lower letter a and corresponding upper letter A
sh-4.2$ main
Enter the chracter: b
Given lower letter b and corresponding upper letter B
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.