Answer to Question #7015 in C++ for muna

Question #7015
Using loop


Write a C++ program that declares a secret word of 5 character and ask the user to find out that word . if the word entered by the user a character is in its correct position then it will appear , otherwise a star will be shown in its location. For example if the secret word is write and the user entered the word think then the program will display **i** . Then if the user enter the word arrive then the program will display *ri** ( the position of the character I was discovered in the pervious step) This process will continue till the user finds the correct word
1
Expert's answer
2012-03-01T09:52:14-0500
#include "stdafx.h"
#include "conio.h"
#include
<iostream>
#include <string>

using namespace
std;

int _tmain(int argc, _TCHAR* argv[])
{
char
character;
string secretword="write";

char findWord[5];
for(int
i=0;i<5;i++){
findWord[i]='*';
}
int count=0;
for(int
i=0;i<secretword.length();i++){
cout<<findWord[i];
}

do{
cout<<"\nEnter
character:";
cin>>character;
for(int
i=0;i<secretword.length();i++){
if(character==secretword[i]){
findWord[i]=character;
count+=1;
}
}
for(int
i=0;i<secretword.length();i++){
cout<<findWord[i];
}
if(count==5){
cout<<"\n\nYou
are right";
cout<<"\nPress any key to
exit...";
break;
}
}while(character!='q');

getch();
return
0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS