Question
COVERT TO C++ C# CODE using System; using System.IO; namespace TestConsole { class Program { static void Main(string[] args) { String origWord = ; String
COVERT TO C++
C# CODE
using System; using System.IO; namespace TestConsole { class Program { static void Main(string[] args) {
String origWord = ""; String letter = ""; bool dashReplaced = false; bool gameOver = false; int numIncorrect = 0; int guessesLeft = 10; String guessWord = ""; int numChars = 0; String usedLetters = ""; int usedSub = 0; int wordCount = 25; string[] originalWords = new string[25];
/* for (var i = 0; i < 25; i++) { Console.Clear(); Console.WriteLine("Enter " + wordCount + " Original words"); originalWords[i] = Console.ReadLine(); wordCount--; }*/ //Read words from file StreamReader read = new StreamReader(@"C:\Users\NarendraPC\Documents\Visual Studio 2017\Projects ead words from file in c sharp ead words from file in c sharp\words.txt"); for (var i = 0; i < 25; i++) { originalWords[i] = read.ReadLine(); } read.Close(); Random randomWord = new Random(); int rndWord = randomWord.Next(0, 24); origWord = originalWords[rndWord];
numChars = origWord.Length;
origWord = origWord.ToUpper();
char[] updatedWord = new Char[numChars];
for (int i = 0; i < numChars; i++) { guessWord += "-"; updatedWord[i] = '-'; }//end for
Console.Clear();
Console.WriteLine("WORD GUESS GAME");
while (gameOver == false) { dashReplaced = false;
Console.Write("Used letters: ");
for (usedSub = 0; usedSub < usedLetters.Length; usedSub++) { Console.Write(usedLetters.Substring(usedSub, 1) + " "); }//end for
Console.WriteLine();
Console.WriteLine("Guess this word: " + guessWord);
Console.WriteLine("Enter a letter: ");
letter = Console.ReadLine(); letter = letter.ToUpper();
usedSub = 0;
while (usedSub < usedLetters.Length && usedLetters.Substring(usedSub, 1) != letter) { usedSub++; }//end while
if (usedSub < usedLetters.Length) { Console.WriteLine("You already guessed letter " + letter); } else {
usedLetters += letter;
for (int x = 0; x < numChars; x++) { if (origWord.Substring(x, 1) == letter) {
updatedWord[x] = Convert.ToChar(letter);
dashReplaced = true; }//end if }//end for
guessWord = new String(updatedWord);
if (dashReplaced == true) {
if (guessWord.IndexOf('-') == -1) //check to see if any dashes remain { gameOver = true; Console.WriteLine("Yes, the word is " + guessWord); Console.WriteLine("Great guessing! You win!"); }//end if } else {
numIncorrect++; guessesLeft--;
Console.WriteLine("You have " + guessesLeft + " guesses left.");
if (numIncorrect == 10) {
gameOver = true; Console.WriteLine("Sorry, you lose. You made too many incorrect guesses."); Console.WriteLine("The word is " + origWord); }//end if }//end if }//end if } //end while
Console.ReadLine(); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started