Answer to Question #271028 in C++ for Marie

Question #271028

Write a program that prompts the user to input a string, then convert each lowercase character in it to uppercase,

and all uppercase character to lowercase. You must use character array in implementing your solution.


Sample Run:

Enter a string: Computer PROGRAMMING is Fun!

cOMPUTER programming IS fUN!



No, it’s not!



1
Expert's answer
2021-11-24T13:47:52-0500
#include <iostream>
using namespace std;
void convertOpposite(string & str)
{
int ln=str.length();
for(int i=0;i<ln;i++)
{
if(str[i]>='a' &&str[i]<='z')
str[i]=str[i]-32;
else if(str[i]>='A' && str[i]<='Z')
str[i]=str[i]+32;
}}
int main(){
string str;
cout<<"Enter the string: "<<endl;
cin>>str;
convertOpposite(str);
cout<<str;
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS