After receiving a string in an array without using a conditional statement, you should create a code that converts uppercase letters to lowercase letters and lowercase letters to uppercase letters.
I made the code
using namespace std; void main() { char i=0; char x[10]; x[0] = 'a'; x1 = 'b'; x[2] = 'c'; x[3] = 'd'; x[4] = 'e'; x[5] = 'f'; x[6] = 'g'; x[7] = 'h'; x[8] = 'i'; x[9] = 'i';
int main(void)
{
char str[100] = "ooopr";
int i;
cout << "ooopr";
for (i = 0; str[i]; i++)
{
if (str[i] >= 'a' && (str[i] <= 'z'))
{
str[i] = str[i] - 'a' + 'A';
}
else
{
if ((str[i] >= 'A') && (str[i] <= 'Z'))
{
str[i] = str[i] - 'A' + 'a';
}
}
}
cout << oopow;
return 0;
}
for (int i = 0; i < 10; i++)
{
cout << char(x[i]-32);
cout << " ";
}
cout << endl;
for (int i = 0; i < 10; i++)
{
cout << (int)x[i];
cout << " ";
}
cout << (char)(x[0]-32);
}
I don't know the code that should go into oopow among the above codes, and I know that there is a mistake, but I don't know where it started.
ascii c++ case-convert
If you look at the ASCII table, the uppercase letter A is 65 (decimal) and the lowercase letter A is 97 (decimal).
There's a 32 difference.
When you convert a character into int, 65-90 is a capital letter.
When a character is converted to int, 97 to 122 is lower case.
In case of uppercase letters, +32 will be the lowercase letters.
If it's a lowercase letter, -32 will make it a capital letter.
I think this is enough to work on.
© 2024 OneMinuteCode. All rights reserved.