Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a simple logic game in which the computer choses a random string of chara

ID: 3620880 • Letter: C

Question

create a simple logic game in which the computer choses a random string of characters that the player has to guess. The computer will announce to the player how many characters of the inputted string are in the same location as the hidden string. For this assignment you will use the symbols #, @, %, and ? in the hidden string and allow the player to chose the difficulty. The difficulty will determine how many characters the hidden string will be with a minimum of 3 and a max of 10.


For Example:

The player wants a difficutly of 5 so the computer choses a random string of # # % ? % and the user enters # ? % ? ? %. The computer would tell the player they got 2 right. Then let the player guess again until the get the right answer.


You should also use the following functions:


GetRandom(int max)


returns a random number from 1 to the maximum number. This will allow you to create the hidden string


CheckChar(char letter1, char letter2)


returns a true or false if the two letters match up. Use this to compare each character of the strings.


CheckString(string hidden, string guess)


returns the number of correct guesses. You can then print out the number or if all the characters are correct you can print out a congratulations message.

Explanation / Answer

please rate - thanks #include <iostream>
#include <cstdlib>
#include <cstring>
# define SIZE 10
using namespace std;
void generate_answer(char[],int);
void compare(char[],char[],int &,int &,int);
int main()
{char guess[SIZE],answer[SIZE];
int i,guesses;
int number,exact,inexact, max;

   srand(time(0));
max=15;
while(max>10||max<3)
    {
      cout<<"Enter max characters: ";
      cin>>max;
      if(max>10||max<3)
         cout<<"Max characters must be between 3 and 10 ";
     }

guesses=0;
                            
cout<<" Starting game... ";
cout<<"symbols used are #, @, %, and ? ";
generate_answer(answer,max);
//cout<<answer<<" ";        //testing
do
{

   cout<<"Enter guess: ";
      cin>>guess;
      guesses++;
       compare(guess,answer,exact,inexact,max);
       cout<<exact<<" Exact and "<<inexact<<" Inexact ";
      }while(exact!=max);
    cout<<"Pattern found in "<<guesses<<" attempts. ";
    system("pause");
return 0;
}
void generate_answer(char answer[], int max)
{int i;
char punct[4]={'#','@','%','?'};
for(i=0;i<max;i++)
   answer[i]=punct[rand()%4];
answer[i]='';
return;
}
void compare(char guess[],char answer[],int &exact ,int &inexact,int max)
{int i,j;
bool found[SIZE],used[SIZE];
for(i=0;i<max;i++)
     {found[i]=false;
     used[i]=false;
     }
exact=0;
inexact=0;
for(i=0;i<max;i++)
   if(guess[i]==answer[i])
        {exact++;
        found[i]=true;
        used[i]=true;
        }     
if(exact==max)
   return;
for(i=0;i<max;i++)
    for(j=0;j<max;j++)
      if(i!=j)
         if(!found[j]&&!used[i])        
             if(guess[i]==answer[j])
                {inexact++;
                 found[j]=true;
                 used[i]=true;
                 }
return;
}