Untitled
unknown
c_cpp
3 years ago
7.0 kB
3
Indexable
using System; //ISSUE cINPUT1INT and CINPUT2INT are 0! namespace testconsole { internal class Program { int number = 1234; public int[] list = new int[9877]; public int cInput2int, digit1, digit2, digit3, digit4, cInput1int, randomArrayItem, firstOne, wrong, correct; bool value = false; string playerNumber; public static bool win_; Random rnd = new Random(); static void Main(string[] args) { Program some = new Program(); some.askForNumber(); some.createArray(); some.avoidImposible(); do { some.selectArrayItem(); some.checkForCorrectness(); foreach (int i in some.list) { if (some.list[some.randomArrayItem] != 0) { some.firstOne = some.list[some.randomArrayItem]; some.value = some.compareNumbers(some.firstOne, i, some.cInput1int, some.cInput2int); if (some.value == false) { if (some.list[i] != 0) { if (some.list[i] == 1234) { Console.ReadKey(); Console.WriteLine("YOU ARE THE ONE MESSED UP!"); Environment.Exit(420); } Console.WriteLine("eliminating " + some.list[i]); some.list[i] = 0; } } } } } while (win_ is false); } public void createArray() { // Creates array that ranges from 1234-9876 do { list[number] = number; number = number + 1; } while (number < 9877); } public void avoidImposible() { foreach (int i in list) { if (list[i] != 0) { digit1 = list[i] / 1000; digit2 = list[i] - (digit1 * 1000); digit2 = digit2 / 100; digit3 = list[i] - (digit2 * 100 + digit1 * 1000); digit3 = digit3 / 10; digit4 = list[i] - (digit2 * 100 + digit1 * 1000 + digit3 * 10); if (digit1 == 0 || digit2 == 0 || digit3 == 0 || digit4 == 0) { list[i] = 0; } if (digit1 == digit2 || digit1 == digit3 || digit1 == digit4 || digit2 == digit3 || digit2 == digit4 || digit3 == digit4) { list[i] = 0; } } } } public void askForNumber() { Console.WriteLine("Enter your 4 digit number that does not contain 0's or repeating digits: "); playerNumber = Console.ReadLine(); Console.WriteLine("Enter in '{possitive number},{negative number}' form: "); } public void selectArrayItem() { randomArrayItem = rnd.Next(0, list.Length); if (list[randomArrayItem] != 0) { Console.WriteLine(list[randomArrayItem]); } else { selectArrayItem(); } } public void checkForCorrectness() { //here cInput's are normal string correctnessInput = Console.ReadLine(); string cInput1 = ToSplit(correctnessInput, 0); string cInput2 = ToSplit(correctnessInput, 1); Console.WriteLine("cInput1: " + cInput1 + " cInput2: " + cInput2); int cInput1int = Convert.ToInt32(cInput1); int cInput2int = Convert.ToInt32(cInput2); Console.WriteLine("cInput1int: " + cInput1int + " cInput2int: " + cInput2int); } string ToSplit(string a, int b) { return a.Split(',')[b]; } bool compareNumbers(int a , int b, int otherCorrect, int otherWrong) { correct = 0; wrong = 0; //compares a to b and checks if otherCorrect and otherWrong is mathching gives true or false //numberdigit is a. number2digit is b //spliting a into 4 digits int numberDigit1 = (a / 1000); int numberDigit2 = (a - numberDigit1 * 1000) / 100; int numberDigit3 = (a - numberDigit2 * 100 + numberDigit1 * 1000) / 10; int numberDigit4 = (a - numberDigit2 * 100 + numberDigit1 * 1000 + numberDigit3 * 10); //spliting b into 4 digits int number2Digit1 = (b / 1000); int number2Digit2 = (b - number2Digit1 * 1000) / 100; int number2Digit3 = (b - number2Digit2 * 100 + number2Digit1 * 1000) / 10; int number2Digit4 = (b - number2Digit2 * 100 + number2Digit1 * 1000 + number2Digit3 * 10); if (numberDigit1 == number2Digit1) { correct++; } if (number2Digit1 == number2Digit2 || numberDigit1 == number2Digit3 || numberDigit1 == number2Digit4) { wrong++; } if (numberDigit2 == number2Digit2) { correct++; } if (numberDigit2 == number2Digit1 || numberDigit2 == number2Digit3 || numberDigit2 == number2Digit4) { wrong++; } if (numberDigit3 == number2Digit3) { correct++; } if (numberDigit3 == number2Digit1 || numberDigit3 == number2Digit2 || numberDigit3 == number2Digit4) { wrong++; } if (numberDigit4 == number2Digit4) { correct++; } if (numberDigit4 == number2Digit1 || numberDigit4 == number2Digit2 || numberDigit4 == number2Digit3) { wrong++; } //here the cInputs are 0 (otherCorrect and otherWrong) if (correct == otherCorrect && wrong == otherWrong) { return true; } else { return false; } } public void printArray() { foreach (int i in list) { Console.WriteLine(list[i]); } } } }
Editor is loading...