C
C#14mo ago
Cheetah

✅ I have 5 errors and have 0 ideas on how to fix them :(

Ok so i havve syntax error, '(' expected at line 31 i havev ) expected at line 31 i havve ; expected at line 31 i have cannot implicitly convertt type 'Char' to 'string' on line 29 and cannot implicitly convert type 'string' to 'bool'
using static System.Net.Mime.MediaTypeNames;

namespace Hangman
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("This is a game of hangman, have fun");
List<string> list = new List<string>();
list.Add("Apples");
list.Add("Bees");
list.Add("constable");
string itemone = list[0];
string itemtwo = list[1];
string itemthree = list[2];
string allitems = itemone + itemtwo + itemthree;
Console.WriteLine(allitems);
Random random = new Random();
int randomitem = random.Next(0, 2);




if (randomitem == 0)
{
for (int i = 0; i < itemone.Length; i++)
{
string letter = itemone[i];
string userinput = Console.ReadLine();
if userinput = letter { Console.WriteLine(letter, "_____")};
Console.WriteLine(letter);

};
}


else if (randomitem == 1)
{
for (int i = 0; i < itemtwo.Length; i++)
{
char letter = itemone[i];
Console.WriteLine(letter);
};
}

else if (randomitem == 2)
{
for (int i = 0; i < itemthree.Length; i++)
{
char letter = itemone[i];
Console.WriteLine(letter);
}


}
}
}
}
using static System.Net.Mime.MediaTypeNames;

namespace Hangman
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("This is a game of hangman, have fun");
List<string> list = new List<string>();
list.Add("Apples");
list.Add("Bees");
list.Add("constable");
string itemone = list[0];
string itemtwo = list[1];
string itemthree = list[2];
string allitems = itemone + itemtwo + itemthree;
Console.WriteLine(allitems);
Random random = new Random();
int randomitem = random.Next(0, 2);




if (randomitem == 0)
{
for (int i = 0; i < itemone.Length; i++)
{
string letter = itemone[i];
string userinput = Console.ReadLine();
if userinput = letter { Console.WriteLine(letter, "_____")};
Console.WriteLine(letter);

};
}


else if (randomitem == 1)
{
for (int i = 0; i < itemtwo.Length; i++)
{
char letter = itemone[i];
Console.WriteLine(letter);
};
}

else if (randomitem == 2)
{
for (int i = 0; i < itemthree.Length; i++)
{
char letter = itemone[i];
Console.WriteLine(letter);
}


}
}
}
}
34 Replies
Cheetah
CheetahOP14mo ago
how do i make like the website thing
Thinker
Thinker14mo ago
$paste
MODiX
MODiX14mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Cheetah
CheetahOP14mo ago
BlazeBin - sneylubswxkr
A tool for sharing your source code with the world!
Thinker
Thinker14mo ago
if userinput = letter { Console.WriteLine(letter, "_____")};
This is probably your problem Firstly, the if is missing the () around the condition
Cheetah
CheetahOP14mo ago
where
Thinker
Thinker14mo ago
Secondly, = is assignment, you need == around userinput = letter Thirdly, you're missing a ; after Console.WriteLine(letter, "_____") And you don't need the ; after the }
Cheetah
CheetahOP14mo ago
i removed that one but when i put == at
string letter = itemone[i];
string letter = itemone[i];
more errors come up
Thinker
Thinker14mo ago
that line is fine, except it needs to be a char and not a string
Cheetah
CheetahOP14mo ago
what is char tho
Thinker
Thinker14mo ago
it's a single character of text a string is many characters
Cheetah
CheetahOP14mo ago
2 more errors came up when i changed it to char
Thinker
Thinker14mo ago
what errors
Cheetah
CheetahOP14mo ago
i think its cuz i did userinput == letter and userinput is string the errors operator '==' cannot be applied to operands of type 'string' and 'char' and argument 1. cannot convert from 'chat' to string both line 32
Jimmacle
Jimmacle14mo ago
try calling .ToString() on your letter or turn your user input into a char, which probably makes more sense given the context
Cheetah
CheetahOP14mo ago
didnt work u mean like
Convert.toChar(userinput);
Convert.toChar(userinput);
right theres not another method??
Jimmacle
Jimmacle14mo ago
no i mean literally .ToString() or in that case userInput[0] to get the first character of the input string
Cheetah
CheetahOP14mo ago
dont work tho
SinFluxx
SinFluxx14mo ago
Can you $paste your updated code?
MODiX
MODiX14mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Cheetah
CheetahOP14mo ago
ok
Jimmacle
Jimmacle14mo ago
"dont work" isn't useful information
Cheetah
CheetahOP14mo ago
well i dont know what to tell you nothing changed the two errors are still there could tell you that tho so mb ig
Jimmacle
Jimmacle14mo ago
Convert.ToString(letter); this doesn't do anything on a line by itself also, don't use Convert
Cheetah
CheetahOP14mo ago
why not
Jimmacle
Jimmacle14mo ago
because it's an old API and there's no point
Cheetah
CheetahOP14mo ago
what do i use then??
Jimmacle
Jimmacle14mo ago
call letter.ToString() like i suggested earlier, and you have to either use the result of that directly in your if or put the result in a variable
Cheetah
CheetahOP14mo ago
ok
Jimmacle
Jimmacle14mo ago
it doesn't change what type letter is, it gives you a new value that's the type you want
Cheetah
CheetahOP14mo ago
what? a new value
Jimmacle
Jimmacle14mo ago
yes like var letterString = letter.ToString()
Cheetah
CheetahOP14mo ago
ohhh ok no more errors thank you
Want results from more Discord servers?
Add your server