A console program (guess number)

Source: Internet
Author: User
Tags generator

Using System;
using System.Collections.Generic;
using System.Text;

Namespace Guessnumber
{
    public class Guessthenumber
    {
         public string tryguess (int guess)
         {
            Random generator = new Random ();
            int randomnumber = generator. Next (1, 100);
            if (guess = randomnumber)
             {
                 return "You guessed it right";
           }
            Else {return "sorry. The correct number is "+ randomnumber.tostring" (); }


}
}

Class Program
{
static void Main (string[] args)
{
Console.WriteLine ("Let's play a game called guessing numbers");
Console.WriteLine ("Now please enter your guess number");
Try
{
int myguess = Int. Parse (Console.ReadLine ());
if ((myguess > 100) | | (Myguess < 1))
{
Console.WriteLine ("The number you enter must be between 1-100");
}
Else
{
Guessthenumber GTN = new Guessthenumber ();
Console.WriteLine (Gtn.tryguess (myguess));
}
}
Catch
{
Console.WriteLine ("Please enter the number you guessed.") ");
}

}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.