C
C#6mo ago
Chaqueta ✪

Im a beginner

9 Replies
Chaqueta ✪
Chaqueta ✪6mo 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
Denis6mo ago
Share the code directly $code
MODiX
MODiX6mo 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
Denis6mo ago
$codegif
Denis
Denis6mo 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
Chaqueta ✪
Chaqueta ✪6mo 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 User6mo ago
Message Not Public
Sign In & Join Server To View
Chaqueta ✪
Chaqueta ✪6mo ago
oh ill work on that thanks
Want results from more Discord servers?
Add your server
More Posts
localhost taking extremely long to loadHello, I'm a complete beginner at C# and ASP.NET, I've started a bare-bones project in Visual StudioCaptcha serviceI am implementing an announcement form for our client and I need to implement the Captcha step beforHTTP Basic Auth in BlazorI am working on a Blazor app, how to add HTTP Basic authentication for the app? I don't need Identit(UNITY) [info] Project system initialization finished. 0 project(s) are loaded...2023-12-21 23:56:44.169 [info] Project system initialization finished. 0 project(s) are loaded, and Whose job is it to mutate an object? (Course Management project)Let's say I've got two classes, a `Course` and a `Student` class. Let's say I want to add a `CoursASP.NET CORE MVC For some reason any non png/img files are not being recognized.I have a GLTF file which is a 3D model, when i open it in my brower it gives 404, the dir has a sub Persist data between Quartz ExecutionI need to be able to persist data between instance executions. I have to tie two separate jobs togetHow to Transfer Data from one Form to the other FormHey, is there anyone that can help me? Im pretty new to C# and I need help with something. My problASP.NET MVC How to open Database in SQL Server Management Studio (can't connect server)?Pretty much the title. I have tried to go to the connection string to get the the server name and in✅ Urgent | Cannot update property in EF because another instance with the same key is being trackedHi, so I have following code: Basically I get a batch to update the field ```cs var batch = await c