Earn Higher Grades With Instant Assignment Help.Ask Question!

C++ Programming
(5/5)

To make this function run, you must implement all of the function calls made from the run() function below. Once completed, call this run() function from your main.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

The following code is a word scramble game, that reads a word from a file. It will then rearrange the letters in the word and output the scrambled word to the console. The user will then try to guess what the word is. The program will output whether or not the user guessed the word correctly. To make this function run, you must implement all of the function calls made from the run() function below. Once completed, call this run() function from your main.

void run()
{
    srand(time(NULL));
    std::ifstream in;
    std::string word, guess;
    openFile(in, "words.txt");
    do{
        std::string ogWord, guess;
        int tries = 4;
        word = getWordFromFile(in);
        ogWord = word;
        scrambleWord(word);
        showWord(word);
        input(guess);
        if(checkWord(ogWord, guess))
            showSuccess();
        else
            showFail();
    }
    while(playAgain());
    in.close();
}

Once you can get the code working, I want you to modify the script so that the user has five tries to guess the correct answer rather than just one.

To get a char  from a string, use the at() function:

 

str::string s = "hello";

s.at(0) // returns 'h'

s.at(1) // returns 'e'

s.at(2) // returns 'l'

s.at(3) // returns 'l'

s.at(4) // returns 'o'

 

Notice that the first letter is at index 0 not 1.


Here is an example of what the output should look like.

Unscramble this word: ebra
bare
Sorry, that is an incorrect answer. You have 4 more times
brae
Sorry, that is an incorrect answer. You have 3 more times
earb
Sorry, that is an incorrect answer. You have 2 more times
brea
Sorry, that is an incorrect answer. You have 1 more time
arbe
Sorry, that is an incorrect answer. Game over
The correct word is bear
Play again? Y/N
y
Unscramble this word: onil
lion
That is the correct answer!
Play again? Y/N
y
Unscramble this word: terig
giret
Sorry, that is an incorrect answer. You have 4 more times
tiger
That is the correct answer!
Play again? Y/N
y

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
631 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
827 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
810 Answers Hire Me