0
I’m trying to do a C# exercise using Windows Forms that are older than 18 years. The algorithm should read the age of 10 people. But when I run the program it lets me just type an age.
public partial class idade : Form
{
int qtde, id,i;
public idade()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
while (i < 10)
{
i = i + 1;
MessageBox.Show("Digite a idade");
id = Convert.ToInt32(txtidade1.Text);
if (id >= 18)
{
qtde = qtde + 1;
}
MessageBox.Show("Existem" + qtde + "pessoas com mais de 18 anos");
}
}
}
}
puts...that dumb I didn’t even think that way...Thank you so much for the help...really mto grateful...sorry but I’m starting in programming.
– Priscila Lepping
It is not to be stupid, you as you are starting in programming have not yet possessed a good logic just... If the answer helped you don’t forget to mark it as Accepted, or the other answers!
– Matheus Ribeiro
yes helped me, I marked as accepted,once again thank you.
– Priscila Lepping
another question if I want to show 2 msgs showing the Qtde of older and younger than 18 years, I will have to create one more variable to store the Qtde of smaller...??
– Priscila Lepping
That’s right and how it’s starting, adopt a pattern for variable names, so you don’t get lost! Create for example, for integers,
int iQtdMaiores, iQtdMenores
, where "i" at the beginning of the name indicates that the variable is of the integer type– Matheus Ribeiro