The program is ok bar the void changecase it displays the string1 fine in output but string2 does not display properly.Does anyone know how to fix this
main()
{
int opt;
cout<<"Please enter first string:";
cin>>string1;
cout<<"Please enter second string:";
cin>>string2;
do{
clrscr();
cout<<" Main Menu"<<endl<<endl;
cout<<"1) Search string for particular character"<<endl;
cout<<"2) Reverse the string"<<endl;
cout<<"3) Change the case of the string"<<endl;
cout<<"4) Reverse and change the case of the string"<<endl;
cout<<"5) Exit program"<<endl;
cout<<"***Please enter your choice***";
cin>>opt;
if(opt == 1)
searcher();
if(opt == 2)
reverse();
if(opt ==3)
chngcase();
if(opt ==4)
{
reverse(),chngcase();
}
}while(opt !=5);
}
//------------------------------------…
void searcher()
{
char ch;
int x=0,fnd=0;
cout<<"Please enter char to search for:";
cin>>ch;
while(string2[x] != '\0')
{
if (string2[x] == ch)
{
cout<<"Found character in position "<<x+1<<" in "<<string1<<string2<<endl;
fnd++;
}
x++;
}
if (fnd == 0) //fnd var same as start so no char match in string?
cout<<"Sorry character not found in "<<string2<<endl;
cout<<"Press any key to continue...";
getch();
}
//------------------------------------…
void reverse()
{
int x,l;
cout<<"The string reversed is:"<<endl;
l=strlen(string2)-1;
cout<<string1;
for(x=l;x>=0;x--)
cout<<string2[x];
cout<<" Press any key to continue...";
getch();
}
//------------------------------------…
void chngcase()
{
int w,m,x,l;
l=strlen(string2)-1;
cout<<"the 2nd string with its case changed:"<<string1;
for(x=l;x>=0;x--)
{
{
if(string2[x]>= 'A' && string2[x] <='Z') //change from upper to lower
w = string2[x];
m=w+32;
cout<<char(m);
}
{
if(string2[x]>= 'a' && string2[x] <='z') //change from lower to upper
w = string2[x];
m=w-32;
cout<<char(m);
}
cout<<endl;
cout<<"Press any key to continue...";
getch();
}
}
//end of for loop
//end of the function change_case()
Additional Details
The part i need fixed is the changecase it takes in two strings (string1,string2) and the the changecase function changes the 2nd from lower to upper or upper to lower it only does this for string2 but in the output it displays both strings eg:"the case with its string changed: bobMARLEY