f the user guesses a letter that is not in the hidden word, display an appropriate message. If the user guesses a letter that appears multiple times in the hidden word, make sure that each correct letter is placed. Figure 6-27 shows a typical game in progress.     Figure 6-27 Typical execution of console-based GuessAWord program

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Microfost Visual C# 7th edition programming exercise 6-10. I need help, please.

 

This problem relies on the generation of a random number. You can create a random number that is at least min but less than max using the following statements:

Random ranNumberGenerator = new Random();
int randomNumber;
randomNumber = ranNumberGenerator.Next(min, max);

Create a game similar to Hangman named GuessAWord in which a player guesses letters to try to replicate a hidden word. Store at least eight words in an array, and randomly select one to be the hidden word.

Initially, display the hidden word using asterisks to represent each letter. Allow the user to guess letters to replace the asterisks in the hidden word until the user completes the entire word.

If the user guesses a letter that is not in the hidden word, display an appropriate message.

If the user guesses a letter that appears multiple times in the hidden word, make sure that each correct letter is placed.

Figure 6-27 shows a typical game in progress.

 

 

Figure 6-27 Typical execution of console-based GuessAWord program

Expert Solution
Step 1

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace GuessAWord

{

class Program

{

static void Main(string[] args)

{

//Array that holds words from file

String[] words = {"welcome", "hello", "program", "interest", "laugh", "object", "oriented", "color"};

char play = 'y';

//Random class object

Random ranNumberGenerator = new Random();

int i;

//Iterate till user wants to stop  

while(play == 'y')

{

//Getting random word

String word;

word = words[ranNumberGenerator.Next(0, 8)];

//Constructing guessing word

String guess="";

//Adding *

for(i=0; i<word.Length; i++)

{

guess += "*";

}

int missCnt = 0;

char ch;

//Playing game

while(!guess.Equals(word))

{

Console.Write("\n(Guess) Enter a letter in word " + guess + " > ");

ch = Console.ReadLine().ToCharArray()[0];         

bool found = false;

//Checking character

for(i=0; i<word.Length; i++)

{

//Comparing

 if(word.ToCharArray()[i] == ch)

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY