Why am I getting a dividing by zero error message
evilrat
evilrat666 at gmail.com
Thu Jan 28 18:54:23 UTC 2021
On Thursday, 28 January 2021 at 18:37:37 UTC, Ruby The Roobster
wrote:
> Here is the output/input of the program:
> Type in data for an egg:
> Width: 3
> Hight: 2
>
> object.Error@(0): Integer Divide by Zero
> ----------------
> 0x004023FE
> 0x0040CF9F
> 0x0040CF19
> 0x0040CDB4
> 0x00409033
> 0x00402638
> 0x75F86359 in BaseThreadInitThunk
> 0x77018944 in RtlGetAppContainerNamedObjectPath
> 0x77018914 in RtlGetAppContainerNamedObjectPath
> Chicken:
>
> Here is the source code:
>
> import std.stdio;
> import std.string;
> void main(){
> egg[1000] data;
> data[0] = (new egg(0,0,"a"));
> for(int i = 1;i<1000;i++)
> {
> int tempx;
> int tempy;
> string tempz;
> int high = 0;
> double highs = 0;
> writeln("Type in data for an egg:");
> write("Width: ");
> readf(" %d",&tempx);
> write("Hight: ");
> readf(" %d",&tempy);
> write("Chicken: ");
> tempz = readln();
> data[i] = new egg(tempx,tempy,tempz);
> for(int x = 0;x < i;x++)
> {
> int tempa;
> int tempb;
> double temp;
> tempa = data[x].x;
> if(tempa < 0)
> tempa-=tempa;
> tempb = data[x].y;
> if(tempb < 0)
> tempb-=tempb;
/*
x starts with 0, you are acessing data[x] which is set to
egg(0,0,"a") and you get div by zero as a result. I see logic
error, though I might be wrong because I haven't actually run
your code.
*/
> temp = tempa / tempb;
> if(temp > highs)
> {
> highs = temp;
> high = x;
> }
> }
> tempx = data[high].x - data[i].x;
> if(tempx < 0)
> tempx-=tempx;
> tempy = data[high].y - data[i].y;
> if(tempy < 0)
> tempy-=tempy;
> }
> }
More information about the Digitalmars-d-learn
mailing list