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:24:10-0500
#include<iostream>
using namespace std;
int main () {
char secret[] = "world";
char word[6];
char tmp[] = "*****";
bool flag = true;
while(1){
flag = true;
cout << "What is the secret word? ";
cin >> word;
cout << endl;
for(int i = 0; i < 5; i++){
if(word[i] == secret[i])
tmp[i] = secret[i];
else
flag = false;
}
for(int i = 0; i < 5; i++)
cout << tmp[i];
cout << endl << endl;
if(flag)
break;
}
cout << "You have found the secret word!" << endl;
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment