plz help this sourcecode............... I want the the output will be like that:
ID: 3616034 • Letter: P
Question
plz help this sourcecode...............I want the the output will be like that: output
enter string:computer science
new string: computer science
enter any letter: Assuming if I write any letter above this newstring calculating number this the letter like that if write (m)the out put must be: 3 because 3 is the third lette ofcomputer science ............... or if i enter letter of (u)the output will be:5 becuse (u) is fourth letter ofcomputer science.............
plz help if it possible.......................
#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 ";
system("pause");
return 0;
} plz help this sourcecode...............
I want the the output will be like that: output
enter string:computer science
new string: computer science
enter any letter: Assuming if I write any letter above this newstring calculating number this the letter like that if write (m)the out put must be: 3 because 3 is the third lette ofcomputer science ............... or if i enter letter of (u)the output will be:5 becuse (u) is fourth letter ofcomputer science.............
plz help if it possible.......................
#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 ";
system("pause");
return 0;
}
Explanation / Answer
please rate - thanks finds all occurrences, not just the first #include using namespace std; int main() {int i,j=0; 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.