Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Pseudocode I need some help double checking what the pseudocode would be, and any inputs, processes/calculations, and outputs for the following. using System; using System.Collections.Generic;

Pseudocode

I need some help double checking what the pseudocode would be, and any inputs, processes/calculations, and outputs for the following.

using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace ConsoleApplication1

{

class Program { static void Main(string[] args) { int score = 0; int correctcounter = 0; int wrongcounter = 0; int guessCounter = 10; // Total number of guess can be done .. char[] correctletters = { 's', 'a', 'm', 'm', 'y' }; char[] wordToReveal = { '*', '*', '*', '*', '*' }; char[] guessedletters = new char[guessCounter]; Console.WriteLine("Welcome to the Hangman Game!"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("You have {0} tries to guess the word right.", guessCounter); Console.WriteLine(); Console.WriteLine(); for (int i = 0; i < guessCounter; i++) { Console.WriteLine("The word is " + string.Concat(wordToReveal) + "."); Console.WriteLine(); Console.WriteLine("Guessed letters: [{0}]", string.Join(",", guessedletters)); Console.WriteLine(); Console.WriteLine("Your total wrong guesses : {0}.", wrongcounter); Console.WriteLine(); Console.WriteLine("Please enter a letter"); Console.WriteLine(); guessedletters[i] = Convert.ToChar(Console.ReadLine()); if (checkGuess(guessedletters[i], correctletters)) { Console.WriteLine(); Console.WriteLine("You guessed correctly!"); for (int j = 0; j < correctletters.Length; j++) { if (guessedletters.Contains(correctletters[j])) { wordToReveal[j] = correctletters[j]; } } correctcounter++; } else { Console.WriteLine(); Console.WriteLine("You guessed incorrectly"); wrongcounter++; } if (correctcounter == correctletters.Length) { Console.WriteLine(); Console.WriteLine("You guessed the word, [{0}]. You WIN!", string.Concat(correctletters)); break; } else { // i reach end of for loop and number of correct guess did not matched to correct letter then user loses if (i == guessCounter - 1) { Console.WriteLine(); Console.WriteLine("You LOSE! The word was [{0}]. You LOSE!", string.Concat(correctletters)); break; } } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Please hit enter to end the program"); Console.ReadLine(); }

// return true when user guess is correct public static bool checkGuess(char guess, char[] correctletters) { for (int i = 0; i < correctletters.Length; i++) { if (guess == correctletters[i]) return true; } return false; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions