PDA

View Full Version : Something I came up with



All that is man
08-30-2009, 03:52 AM
{************************************************* ******************************
function AddUpChange(pennies, nickles, dimes, quaters: integer): extended;
By: All that is man
Description: Adds up the USD 'change' and writelns it out and saves it to result
************************************************** *****************************}
function AddUpChange(pennies, nickles, dimes, quaters: integer): extended;
var
i: integer;
total: extended;

begin
for i := 1 to pennies do total := total + 0.01;
for i := 1 to nickles do total := total + 0.05;
for i := 1 to dimes do total := total + 0.10;
for i := 1 to quaters do total := total + 0.25;
result := total;
Writeln('$'+FloatToStr(result));
end;


Lol, I was counting all my money, and I didn't feel like adding it up in my head.

AddUpChange(60, 13, 41, 59);
$20.1 :D

Thanks for all comments, and help!

senrath
08-30-2009, 03:55 AM
Result is an extended. You're trying to add a String and an Extended together, which doesn't work. Do Writeln('$' + FloatToStr(Result)); instead.

All that is man
08-30-2009, 03:59 AM
FloatToStr

Duh! :facepalm: I was trying ExtToStr haha

Rich
08-30-2009, 04:50 AM
Would you mind if I played around with it a little bit?

All that is man
08-30-2009, 01:02 PM
Would you mind if I played around with it a little bit?

No bro go for it, have fun! As long as I get to see the final product :)

Narcle
08-30-2009, 04:38 PM
function AddUpChange(pennies, nickles, dimes, quarters: integer): extended;
begin
result := pennies*0.01+nickles*0.05+dimes*0.10+quarters*0.25 ;
Writeln('$'+FloatToStr(result));
end;

/bored

All that is man
08-31-2009, 12:46 AM
function AddUpChange(pennies, nickles, dimes, quarters: integer): extended;
begin
result := pennies*0.01+nickles*0.05+dimes*0.10+quarters*0.25 ;
Writeln('$'+FloatToStr(result));
end;

/bored

Wow, you make me look dumb :(

Narcle
08-31-2009, 12:52 AM
Wow, you make me look dumb :(
Sorry hehe, ur way is just unique. ;)

All that is man
08-31-2009, 12:55 AM
Sorry hehe, ur way is just unique. ;)

:D I try my best, haha

HyperSecret
08-31-2009, 01:28 AM
:D I try my best, haha

He is a Dev, that is his job ;). Good job though!

All that is man
08-31-2009, 06:02 AM
He is a Dev, that is his job ;). Good job though!

Haha, thanks