C
C#12mo ago
Rayzenn_

Im a beginner

9 Replies
Rayzenn_
Rayzenn_OP12mo ago
so i am coding a hangman game but i cant figure out how to make it so when theres more than one of the same letter it puts the letter in all the places and not the first index it finds
Denis
Denis12mo ago
Share the code directly $code
MODiX
MODiX12mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Denis
Denis12mo ago
$codegif
Denis
Denis12mo ago
But from what you say it seems that you need to modify one of your loops to traverse all letters of the word and check if the letter provided by the user is present on the current loop index And.your loop should not stop until it reaches the end
Rayzenn_
Rayzenn_OP12mo ago
yeah i figured it would be something close to that but i have close to no idea how to
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hangman
{
class Program
{
static void Main(string[] args)
{
string CorrectWord = "mamamia";
String HiddenWord = "";
int lose = 0;


for (int i = 0; i<CorrectWord.Length; i++)
{
HiddenWord += "_";
}

for (int i = 0; i!=CorrectWord.Length;)
{
Console.WriteLine(HiddenWord);
Console.WriteLine(" Guess a letter");

char guess = Convert.ToChar(Console.ReadLine());
int index = CorrectWord.IndexOf(guess);

if (index != -1)
{
HiddenWord = HiddenWord.Remove(index, 1).Insert(index, guess.ToString());
i++;

}
else if(index == -1)
{
lose++;
}

}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hangman
{
class Program
{
static void Main(string[] args)
{
string CorrectWord = "mamamia";
String HiddenWord = "";
int lose = 0;


for (int i = 0; i<CorrectWord.Length; i++)
{
HiddenWord += "_";
}

for (int i = 0; i!=CorrectWord.Length;)
{
Console.WriteLine(HiddenWord);
Console.WriteLine(" Guess a letter");

char guess = Convert.ToChar(Console.ReadLine());
int index = CorrectWord.IndexOf(guess);

if (index != -1)
{
HiddenWord = HiddenWord.Remove(index, 1).Insert(index, guess.ToString());
i++;

}
else if(index == -1)
{
lose++;
}

}
}
}
}
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Rayzenn_
Rayzenn_OP12mo ago
oh ill work on that thanks
Want results from more Discord servers?
Add your server