Advertisement
AvengersAssemble

Number Guess

Sep 8th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //בבית ספר ממלכתי יצאה שכבה ט' המונה 3 כיתות לטיול. כתוב תכנית המקבלת כקלט את מספר התלמידים בכל כיתה
  6. namespace ConsoleApplication2
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int num;
  13.             char hint1;
  14.             char hint2;
  15.             int guessedNum = 1;
  16.             int n = 10;
  17.             int score = 100;
  18.             bool playAgain = true;
  19.             while (playAgain)
  20.             {
  21.                 hint1 = 'n';
  22.                 hint2 = 'k';
  23.                 Random rnd = new Random();
  24.                 num = rnd.Next(1, 101);
  25.                 //Console.WriteLine(num);// מדפיס מספר רנדומלי לבדיקת תכנית
  26.                 for (int i = 0; i < 7; i++)
  27.                 {
  28.                     Console.WriteLine("Guess number(" + (7 - i) + " guesses left):");
  29.                     guessedNum = int.Parse(Console.ReadLine());
  30.                     if (guessedNum == num)
  31.                     {
  32.                         Console.WriteLine("Great guess!\nSCORE: " +score +"\nPlay again?");
  33.                         i = 8;
  34.                     }
  35.                     if (guessedNum > num)
  36.                         Console.WriteLine(guessedNum + "> random number");
  37.                     if (guessedNum < num)
  38.                         Console.WriteLine(guessedNum + "< random number");
  39.                     else if (guessedNum != num && hint2 != 'h' && (guessedNum >= 1 && guessedNum <= 100))
  40.                     {
  41.                         Console.WriteLine("Wrong! Press 'h' for a hint. Press any othe key then hit 'enter' to guess\nagain.");
  42.                         if (hint1 != 'h')
  43.                         {
  44.                             hint1 = char.Parse(Console.ReadLine());
  45.                             if (hint1 == 'h')
  46.                             {
  47.                                 Console.WriteLine("Number is a " + (Convert.ToString(num)).Length + " digits number.");
  48.                                 n = i;
  49.                                 score-=10;
  50.                             }
  51.                         }
  52.                         if (hint1 == 'h' && n != i)
  53.                         {
  54.                             hint2 = char.Parse(Console.ReadLine());
  55.                             if (hint2 == 'h')
  56.                             {
  57.                                 string strNum = Convert.ToString(num);
  58.                                 Console.WriteLine("The first digit of the number is " + strNum[0] + ".");
  59.                                 score -=20;
  60.                             }
  61.                         }
  62.                     }
  63.                     else if (guessedNum > 100 || guessedNum < 1)
  64.                     {
  65.                         Console.WriteLine("Number out of range! This guess will not count.");
  66.                         i--;
  67.                     }
  68.                     score -=10;
  69.                 }
  70.                 if (guessedNum != num)
  71.                     Console.WriteLine("Too bad! Play again?");
  72.                 Console.WriteLine("y/n");
  73.                 char action = char.Parse(Console.ReadLine());
  74.                 switch (action)
  75.                 {
  76.                     case 'y':
  77.                         playAgain = true;
  78.                         Console.WriteLine();
  79.                         break;
  80.  
  81.                     case 'n':
  82.                         playAgain = false;
  83.                         break;
  84.                 }
  85.             }
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement