I am trying to convert uppercase to lower case and i have to use type casting..
ID: 3531076 • Letter: I
Question
I am trying to convert uppercase to lower case and i have to use type casting.. This is the code so far, it has errors. #include #include using namespace std; int main() { char ch; int number; do { cout <<" Enter a character: "; cin << ch; if (ch>=65 && ch<=90) { // if uppercase number = 32 + static_cast(ch); cout<<static_cast(number) } else if (ch >=97 && ch <= 122){ ch = ch - static_cast(ch); } } while (ch!='0'); return 0; } I would appreciate some help..Explanation / Answer
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main() {
char ch; int number;
do {
cout <<" Enter a character: "; cin >> ch;
if (ch>=65 && ch<=90) {
// if uppercase
number = 32 + static_cast<int>(ch);
//cout<<(char*)(ch+32);
cout<<static_cast<char>(number) ;
}
else if (ch >=97 && ch <= 122)
{ ch = ch - static_cast<int>(ch); }
} while (ch!='0');
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.