Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Simple Question
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Slnj




PostPosted: Sun Sep 19, 2010 3:41 pm   Post subject: 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 Smile. 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.

Quote:

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.

Quote:
public class problem6
{
public static void main (String[] args)
{
double a = 5.75 / 0.13;
double b = a - 5.75;
System.out.println (" The tax on 5.75 is " + a + " , the original price is " + b);
}
}


This is the out put i get

Quote:
The tax on 5.75 is 44.230769230769226 , the original price is 38.480769230769226



Am i doing something wrong? [/quote]
Sponsor
Sponsor
Sponsor
sponsor
techietim




PostPosted: Sun Sep 19, 2010 4:46 pm   Post subject: 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);
    }
}
TheGuardian001




PostPosted: Sun Sep 19, 2010 4:47 pm   Post subject: 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: