Jim Higgins wrote:
> On Sun, 23 Dec 2007 12:08:35 -0500, Joe <joe@[EMAIL PROTECTED]
> wrote:
>
>> +,* and -.
>>
>>
>> var
>> price,total,tax: interger;
>
> Correct the spelling of "integer"
>
> Assuming price and tax are really meant to be integers, you need to
> define total as real or you'll be unable to lose precision.
>
> An item with a PRICE of $4 at a TAX RATE of 6% will have a TOTAL COST
> of $4.24 due to the added TAX AMOUNT of $0.24. Your variables that
> hold these assorted values must be data types that will hold the value
> without losing accuracy or precision.
>
>> write('Price : ');readln(price);
>> write('Tax Rate : ');readln(tax);
>>
>> total:= price * tax;
>
> If a 6% tax (for example) is to be entered as "6" then the calculation
> is:
>
> total := price + price*tax/100
>
> If a 6% tax is to be entered as "0.06" then the calculation is:
>
> total := price + price*tax
>
>> write('Your total is : $', total);
>
> OK, but if you want a decimal value formatted a bit better, try this:
>
> writeln('Your total is : $',total:5:2)
>
> See page 261 in the Programmer's Reference for details on syntax of
> the "write" (and "writeln) procedures for a technically accurate, but
> somewhat confusing description of how to format output.
>
> Note that certain values of price and tax could produce totals with
> three or more significant figures after the decimal. That's messy so
> you'll need to deal with that using the round() function or something
> similar.
>
> After calculating the total above you might try...
>
> total := round(total*100)/100
>
> before writing the formatted total. The line above will take the
> original total and round it off to two significant figures after the
> decimal.
Thanks Jim and Merry Christmas


|