11
Apparently I’m having problems with strings:
public partial class Form1 : Form
{
private int _adicionar;
private int _retirar;
public Form1()
{
InitializeComponent();
}
private void _Random_Click(object sender, EventArgs e)
{
Random num = new Random();
_ValSorteado.Text = num.Next(Convert.ToInt32(_TextValMin.Text), Convert.ToInt32(_TextValMax.Text)).ToString();
if (_Igual.Checked)
{
if (_TextValPalite.Text == _ValSorteado.Text)
{
_adicionar = _adicionar + 1;
_Acerto.Text = Convert.ToString(_adicionar);
}
else
{
_retirar = _retirar + 1;
_Errou.Text = Convert.ToString(_retirar);
}
if (_Maior.Checked)
{
if (_TextValPalite.Text > _ValSorteado.Text)
{
_adicionar = _adicionar + 1;
_Acerto.Text = Convert.ToString(_adicionar);
}
else
{
_retirar = _retirar + 1;
_Errou.Text = Convert.ToString(_retirar);
}
}
if (_Menor.Checked)
{
if (_TextValPalite.Text < _ValSorteado.Text)
{
_adicionar = _adicionar + 1;
_Acerto.Text = Convert.ToString(_adicionar);
}
else
{
_retirar = _retirar + 1;
_Errou.Text = Convert.ToString(_retirar);
}
}
}
}
For equal values (==) and different values (!=) I can, but for higher values (>) or lower values (<) no, it returns the following error:
Operator '>' cannot be Applied to operands of type 'string' and 'string'
How about converting to
int
?– Jéf Bueno
I have made a gist to improve your code a little and solve your problem as well. Take a look, it can help to learn a few things. https://gist.github.com/brunoss/e960713775b4c35ef8f760c10bd0abe6
– Bruno Costa
Did any of the answers solve your problem? Do you think you can accept one of them? If you haven’t already, see [tour] how to do this. You would help the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site.
– Maniero