Thaelith
Thaelith

Reputation: 1

Why can't I put a double value for b here?

I tried something like this but

public static void main(String[] args){
    Scanner Inp = new Scanner(System.in);
    System.out.println("****Bread Store Inventory****");
    System.out.print("Enter the bread amount as the owner of the shop: ");
    int a = Inp.nextInt(); //The bread amount
        if (a < 0) {
        System.out.println("ERROR: Value cannot be negative.");  return;
    }
    System.out.print("Enter the cost of a single bread: ");
    double b = Inp.nextDouble(); //The cost of a single bread
        if (b < 0) {
        System.out.println("ERROR: Value cannot be negative.");  return;
    }
    System.out.println("****Customer User Interface****");
    System.out.print("Welcome to our shop. We have "+a+" breads available. "+"How many would you like? ");
    int c = Inp.nextInt(); //How many breads will the customer buy
        if (c <= 0) {
        System.out.println("ERROR: Value has to be a positive number.");  return;
    }
        else if (a < c) System.out.print("We don't have that many breads at our store, sorry.");
    double d = c*b; //This is cost of the breads that the customer buys.

                if (a >= c) {
                    a -= c;
                    System.out.println("The cost is " +d+".");
                    System.out.println("Thanks for shopping with us today.");
                    System.out.println("We have " +a+ " breads left.");
                }
            }
        }

i cant seem to put a double value for b and i don't know why it says its an inputmismatch but i still couldnt figure it out. Im so new to this so please help me.

Upvotes: 0

Views: 44

Answers (1)

Thaelith
Thaelith

Reputation: 1

The problam was the decimal point so i tried using comma instead and it works!

Upvotes: 0

Related Questions