Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class CSharpOperatorsGame
- {
- static string[] rightAnswer = new string[8];
- static string[] calcAnswer(int levelOfOperator, int arreyIndexOfAnswer, string[,] question)
- {
- for (int i = 0; i < 8; i++)
- {
- if (levelOfOperator == int.Parse(question[1,i]))
- {
- rightAnswer[arreyIndexOfAnswer] = question[0, i];
- arreyIndexOfAnswer++;
- }
- }
- levelOfOperator--;
- if (arreyIndexOfAnswer < 8)
- {
- calcAnswer(levelOfOperator, arreyIndexOfAnswer, question);
- }
- return rightAnswer;
- }
- static void Main()
- {
- string[,] dataBase =
- {
- {"x.y", "f(x)", "a[x]", "x++", "x--", "new", "typeof", "checked", "unchecked", "default", "delegate", "+x", "-x", "!x", "~x", "++x", "--x", "(T)x", "true", "false", "sizeof", "*", "/", "%", "+", "-", "<<", ">>", "<", "<=", ">", ">=", "is", "as", "==", "!=", "&", "^", "|", "&&", "||", "??", "?:", "=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|=", "=>"},
- {"14", "14", "14", "14", "14", "14", "14", "14", "14", "14", "14", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "12", "12", "12", "11", "11", "10", "10", "9", "9", "9", "9", "9", "9", "8", "8", "7", "6", "5", "4", "3", "2", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"},
- {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"},
- };
- string[,] question = new string[3, 8];
- string [] temp = new string [8];
- string input = "";
- string answer = "";
- string checkString = "";
- int numberOfRightToLeft = 0;
- int result = 0;
- Random randomOperator = new Random();
- for (int y = 1; y <= 25; y++)
- {
- numberOfRightToLeft = 0;
- for (int i = 0; i < 8; i++)
- {
- int random = randomOperator.Next(0, 55);
- for (int a = 0; a < 3; a++)
- {
- question[a, i] = dataBase[a, random];
- }
- }
- calcAnswer(14, 0, question);
- for (int i = 0; i < 8; i++)
- {
- if (question[2, i] == "0")
- {
- numberOfRightToLeft++;
- }
- }
- for (int i = 1; i <= numberOfRightToLeft; i++)
- {
- temp[8 - i] = rightAnswer[7 - numberOfRightToLeft + i];
- }
- for (int i = 8 - numberOfRightToLeft; i < 8; i++)
- {
- rightAnswer[i] = temp[i];
- }
- Console.WriteLine();
- Console.WriteLine("Question N{0}:\n", y);
- for (int i = 0; i < 8; i++)
- {
- Console.WriteLine("Operator N{0}: {1}", i + 1, question[0, i]);
- }
- input = "";
- while (input.Length < 8)
- {
- Console.WriteLine();
- Console.WriteLine("Enter your answer (example: 36812457):");
- input = Console.ReadLine();
- }
- answer = "";
- checkString = "";
- for (int i = 0; i < 8; i++)
- {
- answer += rightAnswer[i];
- checkString += question[0, int.Parse(Convert.ToString(input[i])) - 1];
- }
- if (answer == checkString)
- {
- Console.WriteLine("Correct!!!");
- result++;
- }
- else
- {
- Console.WriteLine("Inncorrect!!!");
- Console.Write("Correct answer is: ");
- Console.Write(rightAnswer[0] + " ");
- for (int i = 1; i < 8; i++)
- {
- Console.Write(", {0} ", rightAnswer[i]);
- }
- Console.WriteLine("\n");
- }
- }
- Console.WriteLine();
- Console.WriteLine("Your result is: " + result);
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement