Why am I getting a dividing by zero error message

Ruby The Roobster michaeleverestc79 at gmail.com
Thu Jan 28 18:57:12 UTC 2021


On Thursday, 28 January 2021 at 18:56:45 UTC, Ruby The Roobster 
wrote:
> On Thursday, 28 January 2021 at 18:53:51 UTC, Dennis wrote:
>> On Thursday, 28 January 2021 at 18:37:37 UTC, Ruby The 
>> Roobster wrote:
>>> object.Error@(0): Integer Divide by Zero
>>> Why is this happening? Does anybody know?
>>
>>> data[0] = (new egg(0,0,"a"));
>>
>> Here you set data[0].y to 0
>>
>>> tempb = data[x].y;
>>
>> In the first iteration, this equals data[0].y which equals 0
>>
>>> temp = tempa / tempb;
>>
>> And then you divide by zero here, hence the error
>
> Okay. That worked. I added a check to set temp to zero if tempa 
> or tempb is zero.

Instead of dividing, which causes the bug.


More information about the Digitalmars-d-learn mailing list