Variable is not receiving value - C#

Asked

Viewed 73 times

-1

Please, I need help,

I have three whole variables, one of which receives the result of the division of the other two, but the recipient is not receiving the value, would anyone know why? The two variables involved in the calculation are having their values set normally.

inserir a descrição da imagem aqui

  • Where atual is declared? In this your code, the execution for while, therefore atual is not performed. Post the code snippet where it is declared and where it is changed.

2 answers

1

When doing the division operation int / int, the language rounds down to keep the value as type int.

Contador is 49, maximum is > 49.

A division of an int by a value greater than it will always be less than 0, so the result will be rounded to 0.

Consider changing the type of variables or use a cast for double and retell the test. :)

0

I believe that because it is a division between integers the result of (counter / Maximum) will always be zero for any counter value less than Maximum. Try to convert this operation to real or multiply counter by 100 before splitting by Maximum.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.