Why am I getting a dividing by zero error message
Ruby The Roobster
michaeleverestc79 at gmail.com
Thu Jan 28 18:37:37 UTC 2021
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;
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;
}
}
class egg {
public:
this(uint x,uint y,string name)
{
this.x = x;
this.y = y;
name = cast(string)name;
}
uint x;
uint y;
char[] name;
}
Why is this happening? Does anybody know?
More information about the Digitalmars-d-learn
mailing list