0

My code keeps on skipping to the tip instead of looping back and I don't understand why. I read through the whole thing and everything seems to be working, but when I try to run it allows me to order one item and won't allow me to even decide if I want to order anything else. I'm a beginner to coding so I'm probably missing something obvious.

import java.util.*;

public class OnlineOrdersFallonBryan
{
   public double value = 0;
   public double cost = 0;
   Scanner in = new Scanner(System.in);
   public void main ()
   {
        System.out.println("Welcome to Vegi-Man's Online Ordering!");
        boolean rightorWrong = true;
        while (rightorWrong == true)
        {
        System.out.println("Menu:");
        System.out.println("1. Vegi Burger                $3.00");
        System.out.println("2. Chicken-less Chicken Wings $4.00");
        System.out.println("3. Fried Vegis                $2.00");
        System.out.println("4. Vegan Milkshake            $1.50");
        System.out.println("5. Double Vegi Burger         $5.00");
        System.out.println("6. Onion Rings                $2.00");
        System.out.println("7. Fried Vegi of choice       $2.00");
        System.out.println("8. Vegan Icecream             $1.50");
        System.out.println("9. Vegan Chocolate Lava Cake  $4.50");
        System.out.println("10. Vegan Cheese or Sauces    $0.50");
        System.out.println("");
        System.out.println("Select a menu item: ");
        double menuchoice = in.nextDouble();
        if (menuchoice == 1)
        {
            value = cost + 3;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
        }
        if (menuchoice == 2)
        {
            value = cost + 4;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
        }
        if (menuchoice == 3)
        {
            value = cost + 2;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
        }
            if (menuchoice == 4)
    {
            value = cost + 1.5;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
        }
        if (menuchoice == 5)
        {
        value = cost + 5;
        System.out.println();
        System.out.println("Your current total is $" + cost + ".");
        System.out.println("Options: ");
        System.out.println("1. Order another item.");
        System.out.println("2. Checkout.");
        System.out.println();
        System.out.println("Select an option: ");
        String answer1 = in.nextLine ();
        rightorWrong = answer1.equalsIgnoreCase("yes");
    }
        if (menuchoice == 6)
    {
            value = cost + 2;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
        }
        if (menuchoice == 7)
        {
            value = cost + 2;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
        }
        if (menuchoice == 8)
        {
            value = cost + 1.5;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
            }
        if (menuchoice == 9)
        {
            value = cost + 4.5;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
        }
        if (menuchoice == 10)
        {
            value = cost + 0.5;
            System.out.println();
            System.out.println("Your current total is $" + cost + ".");
            System.out.println("Options: ");
            System.out.println("1. Order another item.");
            System.out.println("2. Checkout.");
            System.out.println();
            System.out.println("Select an option: ");
            String answer1 = in.nextLine ();
            rightorWrong = answer1.equalsIgnoreCase("yes");
        }
    }
    if (rightorWrong == false)
    {
        response1();
    }
    }
   public void response1()
    {
        System.out.println("Subtotal (with tax): $" + value * 1.0825);
        System.out.println("Tip: $");
        double tip = in.nextDouble ();
        double total = value + tip;
        System.out.println("Final Total: $" + total);
    }
}
demongolem
  • 8,796
  • 36
  • 82
  • 101

1 Answers1

0

Solution and explanation of your problem is described here

While we are at it, you should not check if answer is "yes" but rather 1 or 2 because Options are 1. Order another item. and 2. Checkout.

You should use debbuger or at least System.out.println() to see values of relevant variables in your program.

Community
  • 1
  • 1
Bozo5548
  • 26
  • 1
  • 2