-
Notifications
You must be signed in to change notification settings - Fork 0
number guess game
Kristian Virtanen edited this page Oct 31, 2024
·
1 revision
/*
Simple "Guess what number i am thinking of" example.
*/
namespace SmallBasicOpenEditionDll.Classes
{
class TestProgram
{
public static int x = Math.GetRandomNumber(100);
public static int y;
static void Main()
{
TextWindow.Clear();
TextWindow.WriteLine("Hi there.");
TextWindow.WriteLine("\nI am thinking of a number, between 1 and 100");
TextWindow.WriteLine("You'r job is to figure what it is.");
TextWindow.WriteLine("I can only give you clues, is your guess higher or lower than the one i am thinking at.");
TextWindow.WriteLine("With a proper strategy, you should always find it out in max. 7 guesses.");
while (true)
{
TextWindow.WriteLine("Your guess?");
y = (int)TextWindow.ReadNumber();
if (y < x)
{
TextWindow.WriteLine("Try higher.");
}
else if (y > x)
{
TextWindow.WriteLine("Try lower.");
}
else if (y == x)
{
TextWindow.WriteLine("Hey, you got it. Rock on!!!");
Program.End();
}
else {
TextWindow.WriteLine("Some very unexpected input received.");
}
}
}
}
}