Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BIG help here on creating a WORDLE, see my code below. Make the necessary changes before moving on to this nextpart. CORRECTIONS NEEDED before NEXT

BIG help here on creating a WORDLE, see my code below.

Make the necessary changes before moving on to this nextpart.

CORRECTIONS NEEDED before NEXT ITERATION:

1. Program needs to verify that the user entered a 5-letterword. So, the word cat or elephant should not be accepted. Neithershould words that have numbers or special characters in them. Trapthe user in a loop until they enter a word with 5 letters in it. Ifthey enter it in UPPERCASE, change it to lowercase beforeproceeding.

2. Your program only reports on the last guess. It should reporton each letter in all of the guesses.

NEXT ITERATION

For this next iteration, we will simplify our main function byusing additional functions.

Please insert the following functions in your code:

• void displayInstructions() – this function will display theinstructions on how to play the game. This function will not returnanything, and it will not have any parameters.

• string validateUserGuess(string userGuess) – this functionwill validate that the user’s guess is a 5-letter word that doesnot contain numbers or special characters. If the argument passedto this function is not a 5-letter word, the code for prompting theuser for another guess (until the user enters a 5-letter word withno numbers or special characters) should be in this function. Thisfunction will return a 5-letter word. If you need to change thedata types of the return value or the function’s parameter, you maydo so.

• at least one other function of your choosing.

Be sure to add comments to these functions, especially toexplain the purpose and what is passed and returned.

My Code before corrections or next iteration:

#include

#include

using namespace std;

int main() {

string word = "learn"; //target word

cout << "Enter the 5 character wordthat consist of a-z only, you have 6 attempts to win the game"<< endl;

string guess; //user guess word

int i;

cout << "Enter 6 guesses" <

for (int i = 0; i < 6; i++) { //giving 6chances to user

cout << "Enterguess - " << i + 1 << endl;

cin >>guess;

}

const char * firstString = "word";

const char * secondString = "guess";

int match_spot = 0; // correct spot

int present_spot = 0; // present but wrongspot

for (int i = 0; i< 5; i++) {

if (word[i] == guess[i]) {

match_spot++;

}

else {

for (int j = 0; j < 5; j++) {

if (guess[i] == word[j]) {

present_spot++;

break;

}

}

}

}

cout << "Number of letters at correctspot = " << match_spot << endl;

cout << "Number of letters present intarget word but at wrong spot = " << present_spot <

cout << "Number of letters not presentin target word = " << (5 - (match_spot + present_spot))<< endl;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students also viewed these Programming questions

Question

How do the two components of this theory work together?

Answered: 1 week ago

Question

Explain the term learning organization. AppendixLO1

Answered: 1 week ago