c# - Guessing Game and Number Comparison -
I do not understand how to compare numbers in a file with the number given in the function.
This is my code:
using the system; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.IO; Namespace Guess_Game {class program {static zero main (string [] args) {int volume; Int Min, Max; Console.light line ("Enter number of numbers:"); Volume = int.Parse (Console.ReadLine ()); Console.light line ("Enter the maximum and minimum number you want to be in your file: \ n"); Console.light line ("MIN:"); Min = int.Parse (Console.ReadLine ()); Console.light line ("max:"); Max = int.Parse (console .readline ()); Console.light line ("now, approximate number:"); Int number = int.Parse (Console.ReadLine ()); Console WrightLine ("Now a number seems to already contain a file:"); Number = int.Parse (Console.ReadLine ()); GuessGame (minimum, maximum, volume, number); // if (number! = // the number is not equal to the number in which there is a file .. how to write it // if condition ..} static zero GuessGame (int min, int max, int quantity, int number) (Int i = 0; i) for random R = new random (); serial SW = new streamer (@ "D: \ nasir \ sounds game sounds \ bin \ debug \" game.txt); & Lt; volume; i ++) {int temp = r.Next (minimum, max); sw.WriteLine (temp);} while (number! = Sw.WriteLine ()) {Console.WriteLine ("Your guess is wrong Is! ");} Sw.Close ();}}}
Every time you're rolling the dice (inappropriate, IMO) and does not read that file, but just writes it. Let's start with this:
Fixed zero main Getinput ("Enter the number of three: S," maxTries out); GetInput ("Enter the minimum number" : ", MinValue out); GetInput (" Enter maximum number: ", maxValue out); Int Magical = R. Next (Minvalue, Maxwell); // Only once (int i = 1; i & lt; = maxTries; i ++) {GetInput ("Enter your guess:", estimate); If (estimate == magical) {lucky = true; break; }} Console. Wrightite ("you.Lucky = {0};", lucky); Console.ReadLine (); } Fixed zero GetInput (string text, outside variable variable) {console. Write (text); // Scroll to avoid stackoverflow.com while (! Int32.TryParse (Console.ReadLine (), outside variables)); }
If you want to get your number from a file, try something like this:
list & lt; Int & gt; Magical = new list & lt; Int & gt; (); (StreamReader Reader = New Stream Reader ("GuessGame.txt")) {int magical = 0; String line = ""; While (! String.IsNullOrEmpty (line = reader.ReadLine ())) {if (Int32.TryParse (Magical, Out of Magic)) Magical. Add (magical); }}
And the test is such as:
If (magical. Canton (approximate))
Comments
Post a Comment