C
C#9mo 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
Cheetah9mo ago
how do i make like the website thing
Thinker
Thinker9mo ago
$paste
MODiX
MODiX9mo 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
Cheetah9mo ago
BlazeBin - sneylubswxkr
A tool for sharing your source code with the world!
Thinker
Thinker9mo ago
if userinput = letter { Console.WriteLine(letter, "_____")};
This is probably your problem Firstly, the if is missing the () around the condition
Cheetah
Cheetah9mo ago
where
Thinker
Thinker9mo 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
Cheetah9mo ago
i removed that one but when i put == at
string letter = itemone[i];
string letter = itemone[i];
more errors come up
Thinker
Thinker9mo ago
that line is fine, except it needs to be a char and not a string
Cheetah
Cheetah9mo ago
what is char tho
Thinker
Thinker9mo ago
it's a single character of text a string is many characters
Cheetah
Cheetah9mo ago
2 more errors came up when i changed it to char
Thinker
Thinker9mo ago
what errors
Cheetah
Cheetah9mo 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
Jimmacle9mo ago
try calling .ToString() on your letter or turn your user input into a char, which probably makes more sense given the context
Cheetah
Cheetah9mo ago
didnt work u mean like
Convert.toChar(userinput);
Convert.toChar(userinput);
right theres not another method??
Jimmacle
Jimmacle9mo ago
no i mean literally .ToString() or in that case userInput[0] to get the first character of the input string
Cheetah
Cheetah9mo ago
dont work tho
SinFluxx
SinFluxx9mo ago
Can you $paste your updated code?
MODiX
MODiX9mo 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
Cheetah9mo ago
ok
Jimmacle
Jimmacle9mo ago
"dont work" isn't useful information
Cheetah
Cheetah9mo 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
Jimmacle9mo ago
Convert.ToString(letter); this doesn't do anything on a line by itself also, don't use Convert
Cheetah
Cheetah9mo ago
why not
Jimmacle
Jimmacle9mo ago
because it's an old API and there's no point
Cheetah
Cheetah9mo ago
what do i use then??
Jimmacle
Jimmacle9mo 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
Cheetah9mo ago
ok
Jimmacle
Jimmacle9mo ago
it doesn't change what type letter is, it gives you a new value that's the type you want
Cheetah
Cheetah9mo ago
what? a new value
Jimmacle
Jimmacle9mo ago
yes like var letterString = letter.ToString()
Cheetah
Cheetah9mo ago
ohhh ok no more errors thank you
Want results from more Discord servers?
Add your server
More Posts