In C++ , given, string words = "OO/CC II/ZZ";
How do you make it so if user inputs Z, you replace of the Z with ' ' and return
words = "OO/CC II/Z ";
and if the user inputs another Z then it returns
words = "OO/CC II/ ";
but if the user inputs Z for the third time, it makes the user re-enter another character and shows a retry message.
Here is the desired output
And here is the C++ Code
#include <iostream>
#include <string>
using namespace std;
int main()
{
char words[] = "OO/CC II/ZZ", ch, choice;
int i=0;
J:
cout<<"Do you want to enter the character Z? Y for YES or N for NO\n";
cin>>choice;
if((int)choice==(int)'Y')
{
cout<<"Enter Z \n";
cin>>ch;
}
if((int)ch==(int)'Z')
{
i++;
}
switch(i)
{
case 1: words[10]=' ';
cout<<words<<endl;
goto J;
break;
case 2: words[9]=' ';
cout<<words<<endl;
goto J;
break;
case 3: cout<<"Enter another character other than Z\n";
cin>>ch;
if(ch!=(int)'Z')
cout<<"retry again"<<endl;
else
cout<<"Don't enter Z again";
goto J;
default: cout<<"Choice not available";
}
return 0;
}
A humble request. If you liked the answer please don't forget to like or upvote it. Your appreciation motivates experts to help other students too. Thank you :)
Get Answers For Free
Most questions answered within 1 hours.