3
I’m trying to apply a repetition using the while
also using the IF condition, which returns a message to the user if they enter an invalid value. Note that I write nothing inside the while
, but the code works exactly as I hope. Despite this, the fact that I have not put anything inside the while
It makes me sick, it feels wrong somehow. Could you consider whether it’s the most appropriate or whether there’s a better way to solve situations like this?
string dia;
string mes;
do
{
Console.WriteLine("Em que dia você nasceu?");
dia = Console.ReadLine();
if (Convert.ToInt32(dia) > 31)
{
Console.WriteLine("Digite dia válido");
}
}
while (Convert.ToInt32(dia) > 31);
{
//repare que aqui eu não escrevo nada
}
do
{
Console.WriteLine("Em que mês você nasceu?");
mes = Console.ReadLine();
if (Convert.ToInt32(mes) > 12)
{
Console.WriteLine("Digite mês válido");
}
}
while (Convert.ToInt32(mes) > 12);
{
//repare que aqui eu não escrevo nada
}
Dude, what an amazing answer! I’m going to apply this logic here and I’ll also do the exercise you proposed. Thank you so much for clarifying my question.
– Gerson Bueno
If you have specific questions about the improvement you make you can post here that we help.
– Maniero
To implement the modifier out in my github project.com/gebueno/Minhacalculadoradesignos I will have to modify the methods that receive the values of day and month, correct? I tried all night to understand how this modifier works but I couldn’t apply to my project.
– Gerson Bueno
@Gersonbueno https://answall.com/q/82630/101 see if it helps. Almost everything you want to know has been answered here. If you don’t have an opportunity to ask a new question.
– Maniero