Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need to find discount

    Hi, I'm trying to find the bill amount after a bill is discounted by 5% if it is less than 2000, and 15% if it is more than 2000. However, when I put 500, I should get 475.00, but I get 250.0. What am I doing wrong?

    Code:
    import java.util.*;
    
    public class Discount
    {
        public static void main(String args[]) {
            
            //initiate console
            Scanner console = new Scanner(System.in);
            
            //initiate variables
            System.out.print("Enter the original bill amount: ");
            double billTotal = console.nextDouble();
       
            calculateTotal(billTotal);
                
            
      
        } 
        
        public static void calculateTotal(double billTotal) {
            
            double billAmount = 0;
            
            //figure out bill amount
            if (billTotal > 2000) {
                billAmount = billTotal * .15;
            }
            
            if (billTotal <= 2000) {
                billAmount = billTotal * .5;
            }
            
            System.out.println("Bill ater discount :: " + billAmount);
            
        }
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    0.5 is equivalent to 50%; you need to use 0.05 for 5% discount.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •