I need to write a program for calculating the resistance with parallel connections (but what the problem is, the result of 0 comes out although this is wrong) where it is not correct C bülder

{int sopr1, sopr2, sopr3, sopr4, sopr5; float result; sopr1=StrToInt(Edit1->Text); sopr2=StrToInt(Edit2->Text); sopr3=StrToInt(Edit3->Text); sopr4=StrToInt(Edit4->Text); sopr5=StrToInt(Edit5->Text); result=((1/sopr1)+(1/sopr2)+(1/sopr3)+(1/sopr4)+(1/sopr5)); Edit6->Text=FloatToStr(result); } 
  • you do not learn from your mistakes. You have the same thing again - you divide an integer by an integer, and as a result you also get an integer. replace 1 / sopr1 with 1.0 / sopr1 (and all others too) - DreamChild
  • sorry do not tell me how to calculate the sine of any angle in the bulder - parol

1 answer 1

1) Bülder si - no such, apparently it is with ++ builder. 2) the result of the expression 1/sopr1 will be equal to 0 (there may of course be an option when this is not the case). Because when dividing two integers, the result will be an integer. and your result will be whole! These are basic things. It needs to be learned at the very beginning.

There are two possible solutions - either to make all the variables float, or to divide correctly.

 result=((1.0/sopr1)+(1.0/sopr2)+(1.0/sopr3)+(1.0/sopr4)+(1.0/sopr5)); 

But it seems to me that this formula does not count resistance correctly.

  • @KoVadim @parol adds conduction (which is correct when connected in parallel), but forgets to translate the resulting conductivity back into resistance. - alexlz
  • sorry do not tell me how to calculate the sine of any angle in the bulder - parol
  • @parol use library function to calculate sin() sinus - gecube
  • one
    @alexlz yes I know. All the same, the pair went. @gecube and maybe he needs sinf, which works with float. just sin works with double (but this is true for pure si, where there was no overload, just sin in the pros). Although if he has a si bülder, then I don’t know ... - KoVadim