Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*
- * Max Nikoskinen
- * C# Perusteet 2019 syksy
- * HKK
- * PVM: 6.9.2019
- */
- Console.Title = "Arvauspeli";
- //Muuttujat
- List<int> values = new List<int>();
- Random rnd = new Random();
- int correctAnswer = rnd.Next(1, 1000);
- int answer;
- int counter = 0;
- bool gameOn = true;
- string inputValue = " ";
- int addValue;
- while (inputValue != "")
- {
- while (gameOn)
- {
- counter++;
- try
- {
- Console.Write("Arvaappa numero väliltä 1-1000: ");
- answer = int.Parse(Console.ReadLine());
- }
- catch
- {
- Console.WriteLine("Piti syöttää kokonaisluku");
- Console.ReadLine();
- return;
- }
- //Jos arvaus on pienempi kuin oikea vastaus
- if (answer < correctAnswer)
- {
- Console.WriteLine("Luku on suurempi kuin arvauksesi, arvaa uudelleen");
- }
- //Jos arvaus on suurempi kuin oikea vastaus
- else if (answer > correctAnswer)
- {
- Console.WriteLine("Luku on pienempi kuin arvauksesi, arvaa uudelleen");
- }
- //Jos arvaus menee oikein
- else
- {
- Console.WriteLine();
- Console.WriteLine("Arvasit oikein! Arvasit {0} kertaa", counter);
- gameOn = false;
- }
- }
- }
- //Arvaukset
- Console.WriteLine("Arvauksesi:");
- for (int i = 0; i < values.Count(); i++)
- {
- Console.Write("{0} {1} ", i, values[i]);
- }
- //Poistu
- Console.WriteLine("Paina enter lopettaaksesi");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement