Don't like ads? PRO users don't see any ads ;-)
Guest

Random Char

By: a guest on Apr 30th, 2012  |  syntax: C#  |  size: 0.98 KB  |  hits: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Program
  2.     {
  3.         public static bool name(string user, char random)
  4.         {
  5.             for (int i = 0; i < user.Length; i++)
  6.             {
  7.                 if (user[i] == random) // פה זה רושם טעות ..
  8.                 {
  9.                     return true;
  10.                 }
  11.             }
  12.             return false;
  13.         }
  14.  
  15.         static void Main(string[] args)
  16.         {
  17.             char[] words = { 'a', 'b', 'c', 'd', 'e',
  18.                 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  19.             'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  20.             Random randnum = new Random();
  21.             int rand = randnum.Next(0, words.Length + 1);
  22.             char random = words[rand];
  23.             string user = Console.ReadLine();
  24.             bool flag = name(user, random);
  25.             if (flag)
  26.                 Console.WriteLine("The random word is in your name!!");
  27.             else
  28.                 Console.WriteLine("false");
  29.         }
  30.     }