samedi 25 mars 2017

C# random number and greater than operator

I'm trying to generate a random number and give the user 5 tries to guess the right number. I want to compare their guess and tell them if they're too high or too low. VS wont execute and I don't understand why I'm getting errors.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NumberGuessingGame
{
class Program
{
    static void Main(string[] args)

    {
        bool keepGoing = true;
        while (keepGoing)
        {
            Random rnd = new Random();
            int randomnumber = rnd.Next(1, 100);

            //PC tells user to pick a number, display guessed number


            Console.Write("Guess any integer between 1 and 100: ");
            int userentry = Console.ReadLine();


            {

                if (int.Parse(userentry > rnd.Next))
                { Console.WriteLine($"You entered {userentry}. That's too 
high. Try again.");
                    keepGoing = true;

                }

                if (int.Parse(userentry < randomnumber))
                {
                    Console.WriteLine($"You entered {userentry}. That's too 
low. Try again.");
                    keepGoing = true;
                }

                if (int.Parse(userentry = randomnumber))
                {
                    Console.WriteLine($"You entered {userentry}. That's 
right. Good job.");
                    keepGoing = false;
                }

                else (keepgoing) > 5);

                {
                    Console.WriteLine($"You've already tried 5 times. You 
lose.");
                    keepGoing = false;
                }

                else
                {
                Console.WriteLine("That is not a valid number.");
            }


        }
    }
}

}




Aucun commentaire:

Enregistrer un commentaire