title: How to create a java code for calculating the menu prices using if else and while loop
body: <p>I need to create a code using java.
  When any person enters this beverage shop, it shows how to select and order the menu items and quantity. After selecting one menu, code asks "Do you want to select another menu item". If you don't want another menu enter (-1). After entering (-1) price calculate through the code.The balance is over 1000/=  the shop gives 10% discount. The service charge(20%) and VAT(12%) must be added to the balance. </p>
  
  <p>I have created a java code but it does not stop when user enter(-1) and I selected any one menu with one quantity, it shows the balance is 0.0
  What is the error of my code.</p>
  
  <pre><code> Scanner scan=new Scanner(System.in);
    int i=0;
    double tot=0,price,vat,service,res=0,result;
   System.out.println("\t\t\t\tWELCOME TO BEVERAGE SHOP");
   System.out.print("User Name:");
   String name=scan.next();
   System.out.println("Hello!!!"+" "+name+" "+"Welcome...");
   System.out.print("\n");
   System.out.println("Please see our menu and select");
   System.out.print("\n");
   System.out.println("|\tPRODUCT ID\t|\t\tPRODUCT NAME\t\t|\tPRICE(LKR)\t|\n|\t1\t\t|\t\tTea\t\t\t|\t80\t\t|\n|\t2\t\t|\t\tCoffee\t\t\t|\t100\t\t|\n|\t3\t\t|\t\tIce Coffee\t\t|\t150\t\t|");
   System.out.print("\n");
   System.out.println("If you have selected the items you want,you can enter the product below");    
   while(i&gt;=0){
       System.out.print("Product Id:");
       int id=scan.nextInt();
       System.out.print("Qyantity:");
       double quan=scan.nextDouble();
  
       System.out.println(id +":"+quan);
  
       System.out.print("if you want to stop entering id and buy, please enter \"(-1)\" \nor you want to continue enter anothe number:");
       int no=scan.nextInt();
       if(no==-1){
             vat=(res*12)/100;
             service=(res*20)/100;
             result=vat+service;
        System.out.println("Your Amount is:"+" "+result);
             if(res&gt;1000){
             price=(res*10)/100;
             vat=(res*12)/100;
             service=(res*20)/100;
             result=(vat+service)-price;
             System.out.println("Your Amount is:"+" "+result);
             }
       }
       else{
  
           switch(id){
                case 1:
                    tot=80*quan;
                    break;
                case 2:
                    tot=100*quan;
                    break;
                case 3:
                    tot=150*quan;
                    break;   
         }
              res+=tot;  
       }  
   }
    i++; 
  </code></pre>
  
  <p>}
  }</p>