C
C#3mo ago
Owltávio

Could anyone tell me what i'm doing wrong here?

Trying to do a class assignment and not understanding what I'm doing wrong...
No description
8 Replies
Buddy
Buddy3mo ago
$details
MODiX
MODiX3mo ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, what you expect the result to be, what .NET version you are using and what platform/environment (if any) are relevant to your question. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Buddy
Buddy3mo ago
Do you want us to guess what your problem is? You need to provide more details on what isn't working. == is an equal comparison A single = sets the value __ && is AND || is OR == is EQUALS != is NOT EQUALS >= is GREATER OR EQUALS <= is LESSER OR EQUALS < is LESSER > is GREATER All of which return a boolean (true or false) Random's Next is also exclusive, so it actually returns a random integer from 1 to 4 based on your code.
Owltávio
Owltávio3mo ago
Oh sorry. Well, the assigment is to bassically make a 5 player turtle race, i'm trying simulate the turtle reducing and increasing their speed with a Random number generator and switch case, but I keep getting a error message saying "A switch expression of type `System.Random' cannot be converted to an integral type, bool, char, string, enum or nullable type.", so I wanted to know what I'm doing wrong there.
Buddy
Buddy3mo ago
Ah, I see. you don't save down the result into a variable when you call accel.Next(1, 3); And you don't use said result in the switch-statement You try to make a switch expression on Random type, which is not expected.
Owltávio
Owltávio3mo ago
Oh okay, so I can't use the result result in the switch case.
Buddy
Buddy3mo ago
Not sure what you mean there, but Random has no reference of previous value, so calling accel.Next(..) without saving down the value is faulty.
Owltávio
Owltávio3mo ago
Oh, i get it now Thanks for explaning. Yeah, that was the problem, thanks for the help.