Strange results adding two doubles
First, I am really new to Java. So, thanks for any help. Second, I put this in this forum because I didn't see a "N00bs Post Here" forum.
I am trying to do this excercise from a book. What happens is that instead of adding the monthlyRate and tax variables, total ends up bein the two numeric figures printed out together. In this case: 29.953.74375. I'd rather have it do the math.
Thanks for your help.
public class CellCalc {
public static void main(String[] args) {
double monthlyRate = 29.95;
int monthlyMin = 300;
int minUsed = 295;
double overageRate = .45;
double taxRate = .125;
double overageCharge = 0.00;
double total;
double tax;
System.out.println("Your monthly charge is " + monthlyRate + " for " + monthlyMin + ".\n");
System.out.println("This month you used " + minUsed + ".\n");
if (minUsed < monthlyMin){
System.out.println("You incurred no(0) overage.\n\n");
tax = (monthlyRate * taxRate);
total = (monthlyRate + tax);
System.out.println("Your total is " + monthlyRate + tax + ".");
}
}
}





Never mind. Logic error, or rather lack of logic error.
Changed "System.out.println("Your total is " + monthlyRate + tax + ".");"
to
System.out.println("Your total is " + total + ".");