(else. if. random) kullanılarak (c# windowsformapp) ile sayı bulma oyunu yapmam gerekiyor yeni nakil geldiğim için hiçbir bilgim yok yardım edebilecek varmı
(else. if. random) kullanılarak (c# windowsformapp) ile sayı bulma oyunu yapmam gerekiyor yeni nakil geldiğim için hiçbir bilgim yok yardım edebilecek varmı
I am making a random number guessing game which the computer thinks of a number between 1-100. It then asks you what it is and tells you if you are right or wrong. However, whenever I debug, it say...
I am making a random number guessing game which the computer thinks of a number between 1-100. It then asks you what it is and tells you if you are right or wrong. However, whenever I debug, it say...
int val = r.Next(1, 100);
int guess = 0;
bool correct = false;
Console.WriteLine("I'm thinking of a number between 1 and 100.");
while (!correct)
{
Console.Write("Guess: ");
string input = Console.ReadLine();
if (!int.TryParse(input, out guess))
{
Console.WriteLine("That's not a number.");
continue;
}
if (guess < val)
{
Console.WriteLine("No, the number I'm thinking is higher than that number.");
}
else if (guess > val)
{
Console.WriteLine("No, the number I'm thinking is lower than that number.");
}
else
{
correct = true;
Console.WriteLine("You guessed right!");
}
}
I am making a random number guessing game which the computer thinks of a number between 1-100. It then asks you what it is and tells you if you are right or wrong. However, whenever I debug, it say...
stackoverflow.com
Mesaj otomatik birleştirildi:
Random r = new Random();
int val = r.Next(1, 100);
int guess = 0;
bool correct = false;
Console.WriteLine("I'm thinking of a number between 1 and 100.");
while (!correct)
{
Console.Write("Guess: ");
string input = Console.ReadLine();
if (!int.TryParse(input, out guess))
{
Console.WriteLine("That's not a number.");
continue;
}
if (guess < val)
{
Console.WriteLine("No, the number I'm thinking is higher than that number.");
}
else if (guess > val)
{
Console.WriteLine("No, the number I'm thinking is lower than that number.");
}
else
{
correct = true;
Console.WriteLine("You guessed right!");
}
}
Random random = new Random();
int value = r.next(100);
check_button_click()
{
int guessedNum = int.Parse(numbertextbox.Text);
if ( guessedNum < value)
{
//kodun buraya
}
else if (guessedNum > value)
{
//kodun buraya
}
else
{
//kodun buraya
}
}
discorddan ulaşabilirsin her türlü yardımı sağlayabilirim
diartios1881
namespace SayiBulmaOyunu
{
public partial class Form1 : Form
{
int rastgeleSayi;
int tahminSayisi;
public Form1()
{
InitializeComponent();
YeniOyunBaslat();
}
void YeniOyunBaslat()
{
Random rastgele = new Random();
rastgeleSayi = rastgele.Next(1, 101); // 1 ile 100 arasında rastgele bir sayı seç
tahminSayisi = 0;
}
private void TahminButton_Click(object sender, EventArgs e)
{
int tahmin;
if (int.TryParse(TahminTextBox.Text, out tahmin))
{
tahminSayisi++;
if (tahmin < rastgeleSayi)
{
DurumLabel.Text = "Daha büyük bir sayı deneyin.";
}
else if (tahmin > rastgeleSayi)
{
DurumLabel.Text = "Daha küçük bir sayı deneyin.";
}
else
{
DurumLabel.Text = $"Tebrikler! {tahminSayisi} tahminde bildiniz.";
YeniOyunBaslat();
}
}
else
{
DurumLabel.Text = "Lütfen geçerli bir sayı girin.";
}
TahminTextBox.Clear();
TahminTextBox.Focus();
}
}
}