java - My conditional isn't working, i'm a beginner programmer -
double = 10;// 10 dollars spend double b = 0;// cost of food double c;// final total double d;// amount of sandwiches c = a-b; string order; scanner sc = new scanner(system.in);
and here i'm trying objective number of sandwiches , multiply it; while number 2 or lower says 1 thing 3 or higher another. problem it's asking me initialize variable 0 d*0 still zero.
system.out.println("that'll 1.06 how many like?"); b = 1.06*d; d = sc.nextdouble(); system.out.println(d <= 2 ?"ok! coming right sir!":"...ok.... thinks you're fatso now."); system.out.println("she hands "+(a-b)+" change"); break;
the problem here:
system.out.println("that'll 1.06 how many like?"); b = 1.06*d; d = sc.nextdouble();
you haven't initialized d
, when multiplication multiplying nothing. need load scanner's value d
before multiply b
.
system.out.println("that'll 1.06 how many like?"); d = sc.nextdouble(); b = 1.06*d;
Comments
Post a Comment