I have tried searching online everywhere and I cant. Basically I wanted to make a program where you have choices of what drinks you want, then when you type the drink, it tells how much it is. I used a while loop so if you enter the wrong price it keeps asking for the right price till you select it. It works fine for my first drink which is "pepsi" but then for when I pick coke, the code just doesnt run at all.. it doesnt even ask for the price.
import java.util.Scanner;
public class BendingMachineTestWhile{
public static void main (String [] args)
{
String drink;
int money;
Scanner kbd = new Scanner (System.in);
System.out.println (" Pick from the following drinks: \n pepsi \n coke \n gatorade");
drink = kbd.nextLine();
while (true){
if (drink.equals ("pepsi"))
{
System.out.println ("That will be 4 dollars");
System.out.println ("Enter 4 dollars");
money = kbd.nextInt();
if ( money == 4 )
{
System.out.println ("Thanks.");
break;
}
else if ( money != 4)
{
System.out.println ("You idiot its four dollars");
}
}
}
if (drink.equals ("coke"))
{
System.out.println ("That will be 6 dollars");
System.out.println ("Enter 6 dollars");
money = kbd.nextInt();
while (true){
if ( money == 6 )
{
System.out.println ("Thanks.");
break;
}
else if ( money != 6)
{
System.out.println ("You idiot its four dollars");
}
}
}
}
}
The second if statement is the one that doesn't work. If you guys could help me it would be really appreciated.