Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //בבית ספר ממלכתי יצאה שכבה ט' המונה 3 כיתות לטיול. כתוב תכנית המקבלת כקלט את מספר התלמידים בכל כיתה
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num;
- char hint1;
- char hint2;
- int guessedNum = 1;
- int n = 10;
- int score = 100;
- bool playAgain = true;
- while (playAgain)
- {
- hint1 = 'n';
- hint2 = 'k';
- Random rnd = new Random();
- num = rnd.Next(1, 101);
- //Console.WriteLine(num);// מדפיס מספר רנדומלי לבדיקת תכנית
- for (int i = 0; i < 7; i++)
- {
- Console.WriteLine("Guess number(" + (7 - i) + " guesses left):");
- guessedNum = int.Parse(Console.ReadLine());
- if (guessedNum == num)
- {
- Console.WriteLine("Great guess!\nSCORE: " +score +"\nPlay again?");
- i = 8;
- }
- if (guessedNum > num)
- Console.WriteLine(guessedNum + "> random number");
- if (guessedNum < num)
- Console.WriteLine(guessedNum + "< random number");
- else if (guessedNum != num && hint2 != 'h' && (guessedNum >= 1 && guessedNum <= 100))
- {
- Console.WriteLine("Wrong! Press 'h' for a hint. Press any othe key then hit 'enter' to guess\nagain.");
- if (hint1 != 'h')
- {
- hint1 = char.Parse(Console.ReadLine());
- if (hint1 == 'h')
- {
- Console.WriteLine("Number is a " + (Convert.ToString(num)).Length + " digits number.");
- n = i;
- score-=10;
- }
- }
- if (hint1 == 'h' && n != i)
- {
- hint2 = char.Parse(Console.ReadLine());
- if (hint2 == 'h')
- {
- string strNum = Convert.ToString(num);
- Console.WriteLine("The first digit of the number is " + strNum[0] + ".");
- score -=20;
- }
- }
- }
- else if (guessedNum > 100 || guessedNum < 1)
- {
- Console.WriteLine("Number out of range! This guess will not count.");
- i--;
- }
- score -=10;
- }
- if (guessedNum != num)
- Console.WriteLine("Too bad! Play again?");
- Console.WriteLine("y/n");
- char action = char.Parse(Console.ReadLine());
- switch (action)
- {
- case 'y':
- playAgain = true;
- Console.WriteLine();
- break;
- case 'n':
- playAgain = false;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement