View Full Version : Some Math help =]
Lance
05-07-2009, 05:09 AM
ok im having some issues D=
program New;
var
AntibanChance : Integer;
const
chance = 50{%}; //The persent chance of doing antiban.
{function AntibanChance : Integer;
begin
Result := (8 / chance) * 100
end;}
procedure Antiban;
begin
case Random(AntibanChance) of
0: Writeln('zero');
1: Writeln('one');
2: Writeln('two');
3: Writeln('three');
4: Writeln('four');
5: Writeln('five');
6: Writeln('six');
7: Writeln('seven');
8: Writeln('eight');
end;
end;
begin
AntibanChance := ((8 / chance) * 100);
Writeln('AntibanChance: ' + IntToStr(AntibanChance)); //this SHOULD be comeing out as 16
Antiban;
end.
my results are always:
Successfully compiled (108 ms)
AntibanChance: 0
zero
Successfully executed
i dont get what im doing wrong ;_;
senrath
05-07-2009, 05:12 AM
You're using integers, so 8 / chance always becomes 0.
Lance
05-07-2009, 05:16 AM
ohhh k i understand now. integers are only whole numbers. what type of variable do i need for this then?
Shuttleu
05-07-2009, 05:16 AM
program New;
var
AntibanChance : Integer;
const
chance = 50; //The persent chance of doing antiban.
{function AntibanChance : Integer;
begin
Result := (8 / chance) * 100
end;}
procedure Antiban;
begin
case Random(AntibanChance) of
0: Writeln('zero');
1: Writeln('one');
2: Writeln('two');
3: Writeln('three');
4: Writeln('four');
5: Writeln('five');
6: Writeln('six');
7: Writeln('seven');
8: Writeln('eight');
end;
end;
begin
AntibanChance := ((8 *100) / chance);
Writeln('AntibanChance: ' + IntToStr(AntibanChance)); //this SHOULD be comeing out as 16
Antiban;
end.
comes out as 16
~shut
Zyt3x
05-07-2009, 05:17 AM
the constant 'Chance' is set to 50. and 8 / 50 is not greater than 0, to solve this problem just do something like 'AntibanChance := ((8 / (Chance / 10)) * 100);'
Lance
05-07-2009, 05:32 AM
the constant 'Chance' is set to 50. and 8 / 50 is not greater than 0, to solve this problem just do something like 'AntibanChance := ((8 / (Chance / 10)) * 100);'
i dont understand.. 8/50 = 0.16 which is bigger than zero
and ok i changed it to AntibanChance := ((8 / (Chance / 10)) * 10); but now every time the value is 10, still not 16. Is scar rounding the values?
and shouldnt there be a special variable that deals with fractions that i could use intead of Integer?
Shuttleu
05-07-2009, 05:34 AM
i dont understand.. 8/50 = 0.16 which is bigger than zero
and ok i changed it to AntibanChance := ((8 / (Chance / 10)) * 10); but now every time the value is 10, still not 16. Is scar rounding the values?
and shouldnt there be a special variable that deals with fractions that i could use intead of Integer?
just look at my post
~shut
tarajunky
05-07-2009, 05:36 AM
Integers are always rounded to the nearest.... integer.
0,1,2,3,4,5... etc.
If you want to use decimals, you need the variable to be "extended".
Then you'll also need to use FloatToStr instead of IntToStr.
Lance
05-07-2009, 05:38 AM
ohh k thanks shut, i didnt see that you had changed my equasion
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.