This is a C# Program to prefix game.
This C# program is used to prefix game.
Here prefix has to be found for the words which are given.
Here is source code of the C# Program to Prefix Game. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Prefix Game */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Project { class Program { static void Main(string[] args) { string[,] seq = new string[4, 3]; int row = 0; seq[row, 0] = "substring"; seq[row, 1] = "sub"; seq[row, 2] = "incorrect"; row++; seq[row, 0] = "input"; seq[row, 1] = "in"; seq[row, 2] = "incorrect"; row++; int numrows = 0; play(seq, numrows); Console.Write("Continue : Press 'y'"); string next = Console.ReadLine(); if (next.CompareTo("y") == 0) { Console.Clear(); numrows += 2; play(seq, numrows); } Console.ReadLine(); } static void play(string[,] seq, int rows) { Console.WriteLine("ENGLISH WORD PREFIX GAME"); for (int i = rows; i <rows+2 ; i++) { Console.Write("What is the correct prefix of '{0}':", seq[i, 0]); string ans = Console.ReadLine(); if (seq[i, 1].ToLower().CompareTo(ans.ToString().ToLower()) == 0) seq[i, 2] = "correct"; Console.WriteLine(); } Console.WriteLine("CHECK YOUR ANSWERS!!!"); Console.WriteLine("Word\t\t\tPrefix\t\tDescription"); for (int i = rows; i < rows+2; i++) { for (int j = 0; j < 3; j++) Console.Write("{0}\t\t", seq[i, j]); Console.WriteLine(); } Console.Read(); } } }
This C# program is used to prefix game. We have already entered the words using seq[] array variable, and perform the play() function by passing the ‘seq’ and ‘numrows’ variable values as an argument.
In play() method, using for loop we are reading the English word prefix. Convert the entered word into lowercase using ToLower() method. If condition statement is used to check the value is equal to correct. If the condition is true then execute the iteration of the loop.
Another if condition statement is used to check the value of ‘given’ variable is equal to ‘y’. If the condition is true then execute the statement. Print the prefix has for the words which are given.
ENGLISH WORD PREFIX GAME What is the correct prefix of 'substring' : sub What is the correct prefix of 'input' : in CHECK YOUR ANSWERS!!!! Word Prefix Description substring sub correct input in correct
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Buy MCA Books
- Buy Computer Science Books
- Practice MCA MCQs