#include<iostream> using namespace std; int main() {int i,j=0; string s; char ne
ID: 3616043 • Letter: #
Question
#include<iostream>
using namespace std;
int main()
{int i,j=0;
string s;
char newstring[100],letter;
char last='1'; //set to anything butblank
cout<<"enter a string: ";
getline(cin,s);
for(i=0;s[i]!='';i++)
{
if(s[i]==' ')
{if(last!=' ')
newstring[j++]=s[i];
}
elseif(s[i]=='('&&s[i+2]==')')
{newstring[j++]=s[i+1];
i+=2;
}
else
newstring[j++]=s[i];
last=s[i];
}
newstring[j]='';
cout<<"new string is: "<<newstring<<endl;
cout<<"enter any letter: ";
cin>>letter;
cout<<"letter"<<letter<<" occurs at positions: ";
for(i=0;newstring[i]!='';i++)
{ if(newstring[i]==letter)
cout<<i+1<<"";
else
cout<<" not found thisletter" ;
}
cout<<endl;
system("pause");
return 0;
}
Explanation / Answer
please rate - thanks using bool. if you haven't learned bool variable found caneasily be changed to an int--message me #include using namespace std; int main() {int i,j=0; bool found=false; string s; char newstring[100],letter; char last='1'; //set to anything butblank coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.