Question

write a C++ to defined language the output should show this answer Enter string aa string...

write a C++ to defined language



the output should show this answer

Enter string
aa
string acceted

enter string
ba
string not accepted
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Since your question is not elaborative enough I am assuming that you need a solution in which we have to accept only those string in which all character is the same. And the user will be inputting string 2 times. You can change the num of iteration as per your choice. I have made it as 2.

Please find the code below:

#include <iostream>

using namespace std;

bool checkString(string s)
{
int len_string = s.length();
for (int i = 1; i < len_string; i++)
if (s[i] != s[0])
return false;
return true;
}
  

int main()
{
string s;
for(int i=0;i<2;i++){
cout<<"Enter string "<<endl;
cin>>s;
if (checkString(s))
cout<<"string acceted"<<endl;
else
cout<<"string not acceted"<<endl;
cout<<"\n";
}

return 0;
}

OUTPUT:

I hope it helps.

In case of any query revert back to me.

Have a great day :)

Add a comment
Know the answer?
Add Answer to:
write a C++ to defined language the output should show this answer Enter string aa string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT