Subject:
addition
Date:
Sat, 17 Feb 2001 00:09:37 -0500
From:
Ken Anderson <
kand@clover.net>
To:
beginning@javaranch.com I am writing some
java for practice and have run into a problem. I am entering several prices of merchandise as if it were checkout register. I was then going to total the merchandise and then figure out the sales tax and finally add the two for the total sale. However I can't get past the first section. No matter if I use int or doubles or floats, I get totals that do not make sense. I know I am missing something easy but I have looked now for several days and can't figure it out, so I think it is now time to look for help!! I have tried different combinations of numbers and they are all goofy.
for example:
I entered 11.00 14.00 22.50 13.00 and got
The purchase price is 11.00
The purchase price is 14.00
The purchase price is 22.50
The purchase price is 13.00
The total price before tax is 44.00
class Hi
{
public static void main(
String[] args )
{
double totPrice = 0.0 ;
double price = Double.parseDouble( args[0] ) ;
for ( int i = 0; i < args.length; i++ )
{
totPrice = totPrice + price ;
System.out.println( "The purchase price is " + args[i] ) ;
}
System.out.println( " __________" ) ;
System.out.println( "The total before tax is "
+ totPrice );
}
}