MasterMind in C# Console Application [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an assignment from my school in which we have to make a MasterMind game in C# in a console application.
So far I managed to do the border (with help from friends), an introductory tune (beep) when the game starts, and the user input to insert the numbers.
The problem is when the user ends the game, the game doesn't stop to accept inputs from the user and obviously crashes.
I also have an error in the high score method "use of unassigned local variable".

score = ptsguesses * ptsTime;
Where are ptsguesses and ptsTime initialized? Nowhere, obviously.
You probably want to set ptsguesses and ptsTime before calculating the score.

the use of unassigned value is probably this one:
static void highscore()
{
{
byte ptsguesses,ptsTime, userGuesses, timeTaken;
int score; <<------
change it to int score = 0;
also, ptsguesses,ptstime,userguesses and timetaken have never been initialised.
you might want to try to pass those arguments to your highscore() method.
something like
static void highscore(byte ptsguesses, byte ptsTime, byte userGuesses, byte timeTaken)
you'd have to call the highscore() method then, and pass the actual values to the method. that way if u try to run highscore(), you will have something to actually calculate.

Related

C# reset many integer variables quicker [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Is there a way to reset these variables quicker like at the time of declaration?
Declaration:
int numa1, numa2, numa3, numd1, numd2, numd3;
Reset afterwards:
numa1 = 0;
.
.
.
numd3 = 0;
Because I will change these variables, but then I need to reset them as 0, OK?
Replying the comments below:
Sorry, I didn't change "Reset afterward" to "Initializes afterward". Someone else did that.
Sorry, but you cannot change the values of the variables like:
numa1, numa2, numa3, numd1, numd2, numd3 = 0;
I tried and I received Error 1, 2, 4.
By quicker if you mean faster, I donot think there is any better alternative.
If you mean reducing some lines,
You can choose either
int numa1=0, numa2=0, numa3=0, numd1=0, numd2=0, numd3 = 0;
or
int numa1, numa2, numa3, numd1, numd2, numd3 = 0;
numa1= numa2= numa3= numd1= numd2= numd3;
I guess that you should have used two arrays, I never had a function that used so many variables with such names (sequential numbers).
If you'd use arrays, Your code will look like this :
int[] numa = new [] {0,0,0,0};
int[] numd = new [] {0,0,0,0};
But this is up to you.
For more information about arrays

Substring compiles but code doesn't work [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
When I use the code below, it compiles but the rest of the code doesn't seem to work. When I take out the Substring part of it, it does.
-Steps
String theDate, theWeekDay;
if (ToTime(Time[0]) == ToTime(0, 0, 0))
{
theDate=ToDay(Time[0]).ToString().Substring(0,3);
theWeekDay=Time[0].DayOfWeek.ToString().Substring(4,8);
DrawTextFixed("day",theWeekDay, TextPosition.BottomRight);
DrawText("day"+Convert.ToString(ToDay(Time[0])),
theWeekDay+" "+theDate,0, Low[0]-TickSize*20, Color.Blue);
}
You haven't given enough information to solve your problem, but if you're just trying to get the day of the week name in the abbreviated format, use this instead:
theWeekDay = Time[0].ToString("ddd");
You're going to have to provide more than just this snippet of code. What is the Time object you're accessing via an indexer? Have you debugged this to see if Time[0] actually has a value? My guess here would be that Time[0] doesn't return a value that DayOfWeek can work with hence Substring(0,3) is being running against either an empty string or a null value
Unless you have omitted part of the code, your assignment does not take place within a class definition or a method.

Eval() javascript code from within C# [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to eval() and run this javascript code from my C# program, but it won't even debug.
How can I do this?
string jsFunc = "eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('8 4=\'6/13!)!6/12))6/19))))2!,!18*!16!15*!,!:14*-!17:9*!,!26***<\';8 5=\"\";20(3=0;3<4.24;3++){10(4.7(3)==25){5+=\'\\&\'}11 10(4.7(3)==23){5+=\'\\!\'}11{5+=21.22(4.7(3)-1)}};5;',10,27,'|||i|s|m|Nbui|charCodeAt|var||if|else|bct|spvoe|521|8477|_|73|2689|njo|for|String|fromCharCode||l{�ength|28|4451'.split('|')))";
JSEval.JSEval eval = new JSEval.JSEval();
string expression, result;
Console.Write("Выражение: ");
expression = jsFunc;
try
{
result = eval.Eval(expression).ToString();
}
catch
{
result = "!!!";
}
One potential problem, if I am permitted to hazard a guess based on the slim details available, is the odd character sequence found in the string:
...||l{�ength|28|4451'.split('|')))";
Perhaps you should remove the {� and re-run the code.
To elaborate on other meanings of the phrase "code don't debug":
Ensure the project is configured to build in Debug mode.
If your expectation is that you can step through the JavaScript, this will not be possible. You should instead debug the JavaScript using something like Firebug.
If you cannot mentally debug the JavaScript, because it has been minified, you should look at a tool to unpack the JavaScript into something more human readable.

Creating a do statement that has the properties of a while statement [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Has been solved. Was trying to create a do statement that would not do anything until the while was checked. Was solved by simply putting an if statement before the do statement.
Using a do statement and anything else you might need, write the equivalent of:
while (b) {
s;
}
I think you might be looking for
if(b)
{
do
{
s;
}
while(b);
}
Is a standard part of the language:
do
{
s;
} while (b);
If I understood your question correctly you have a code that uses do..while loop and you want to replace it with a "regular" while loop.
That is not so simple as you say in your example. The difference is that do..while will always run at least once, and check the condition after it's completed. While loop may not run at all.

How to pass decimal values over serialport in C#? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
how to pass decimal values over serialport control?
Start by convering whatever values that you want to pass into a byte array (System.Byte()), and then use the SerialPort.Write(Byte(), Int32, Int32) overload to write them to the serial port.
That overload allows you to specify the array of bytes that will be passed, the offset of the array at which to begin, and the number of bytes out of the array that should be passed.
Obviously you've looked already, so you know that you are not going to find an overload for the SerialPort.Write method that writes integer or decimal values directly.
Use SerialPort Class.

Categories

Resources