c++ help! Modify the c++ program below such that if one of the whitespaces is en
ID: 3666150 • Letter: C
Question
c++ help! Modify the c++ program below such that if one of the whitespaces is entered, it displays a message and tells what the character was.
// P54.cpp - This program reads one character from the keyboard and will
// convert it to uppercase, if it is lowercase
// convert it to lowercase, if it is uppercase
// display a message, if it is a digit
#include
#include
using namespace std;
int main( )
{
char c;
cout << "Enter a character ";
cin >> c;
if(isalpha(c))
{ //check to see if it is a letter of alphabet
if( isupper(c) ) //check to see if it is uppercase
{
c = tolower(c);
cout << "Your character " << c << " is in uppercase.";
cout << "Its lowercase case is " << c << endl;
}
else
{
c = toupper(c);
cout << "Your character " << c << " is in lowercase.";
cout << "Its uppercase is " << c << endl;
}
}
else
{
cout << "Your character " << c << " is a digit. ";
}
return 0;
}
Explanation / Answer
#include<iostream>
#include<cctype>
using namespace std;
int main( )
{
char c;
cout << "Enter a character ";
cin >> c;
if(isalpha(c))
{ //check to see if it is a letter of alphabet
if( isupper(c) ) //check to see if it is uppercase
{
cout << "Your character " << c << " is in uppercase.";
c = tolower(c);
cout << "Its lowercase case is " << c << endl;
}
else
{
cout << "Your character " << c << " is in lowercase.";
c = toupper(c);
cout << "Its uppercase is " << c << endl;
}
}
else
{
cout << "Your character " << c << " is a digit. ";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.