
-----------------------------------
Slnj
Sun Sep 19, 2010 3:41 pm

Simple Question
-----------------------------------
Hi guys it's been a while since i been on this site, and school just started and i took another computer science class and I'm learning java now :). So anyways my teacher gave me some stuff to program i did all except for one which i tried to program but I'm getting a different answer then what I'm expecting to get.


Write a program that calculates the amount of tax on $5.75 saves it to a new variable and then outputs the information on the screen.

This is what i tried so far.

public class problem6
{
    public static void main (String

This is the out put i get 

The tax on 5.75 is 44.230769230769226 , the original price is 38.480769230769226


Am i doing something wrong? [/quote]

-----------------------------------
techietim
Sun Sep 19, 2010 4:46 pm

Re: Simple Question
-----------------------------------
[code]
public class problem6
{ 
    public static void main (String[] args) 
    { 
        double price = 5.75;
        double tax = price * 0.13; 
        System.out.format ("The tax on $%.2f is %.2f\nTotal:%.2f", price, tax, price + tax); 
    } 
}
[/code]

-----------------------------------
TheGuardian001
Sun Sep 19, 2010 4:47 pm

Re: Simple Question
-----------------------------------
Calculating tax is multiplying by the tax rate, not dividing by.

5.75 * 0.13 = 13/100ths of 5.75 = 0.7475

dividing by any number between 1 and 0 will increase the number. Dividing by 0.13 is the same as multiplying by about 7.7.
