Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Writing a pizza program

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Thanked 0 Times in 0 Posts

    Angry Writing a pizza program

    I'm trying to write a program that will output the total number of large,medium,and small pizza along with the average cost of an order. I'm stuck on this error , "Else without if" on line 48 else ...medium. What is wrong with it? Are my brackets not matching up?

    import java.util.Scanner;

    public class PizzaOrder
    public static void main(String[] args)
    Scanner input = new Scanner (System.in);
    double cost,total, average;
    String name,response,size,type;
    int count,l,m,s;

    System.out.println("Do you wish to order a pizza?");
    response = input.next();

    while (!( response.equals("no")))
    if ( response.equals("yes"))
    System.out.print("Enter your last name in all lower case and then press the ENTER key.");
    name = input.next();
    System.out.print("Enter the size of pizza desired in all lower case and then press the ENTER key. ");
    size = input.next();
    System.out.print("Enter the type of pizza desired in all lower case and then press the ENTER key.");
    type = input.next();

    if (size.equals("small")|| size.equals("medium")||size.equals("large"))
    if (size.equals("small"))
    if (type.equals("pepperoni"))
    cost = 8.50;
    else if (type.equals("cheese"))
    cost = 7.00;
    else if (type.equals("supreme"))
    cost = 11.00;
    cost = 10.00;



    else if (size.equals("medium"))

    if (type.equals("pepperoni"))
    cost = 9.50;
    else if (type.equals("cheese"))
    cost = 8.00;
    else if (type.equals("supreme"))
    cost = 14.00;
    cost = 12.25;


    else ( size.equals("large"))

    if (type.equals("pepperoni"))
    cost = 10.50;
    else if (type.equals("cheese"))
    cost = 9.00;
    else if (type.equals("supreme"))
    cost = 16.00;
    cost = 14.50;


    total = cost;
    average = total/count;

    System.out.println("Last Name: " +name);
    System.out.println("Number of large pizzas ordered: " +(l));
    System.out.println("Number of medium pizzas ordered: " +(m));
    System.out.println("Number of small pizzas ordered: " +(s));
    System.out.println("Number of pizzas ordered: " +(count));
    System.out.println("Average cost of an order: " +(average));



    System.out.println("Word entered is invalid.");

    System.out.print("Do you wish to order a pizza?");
    response = input.next();

    Last edited by superlostdoe; October 9th, 2014 at 07:46 AM.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: Writing a pizza program

    When posting code, please use highlight tags to preserve formatting. Also, use proper indentation to really highlight what's going on. You have a few things that look like this:

    x = 7;
    other stuff

    ...which doesn't make a lot of sense. Maybe you mean to put the "x = 7" part inside the body of the if block?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. help writing this program...
    By javanoobie95 in forum Object Oriented Programming
    Replies: 7
    Last Post: August 25th, 2014, 12:49 PM
  2. Pizza Pickup and delivery ordering java program
    By pointblank12 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 31st, 2014, 07:53 PM
  3. need help with writing this program
    By nickans in forum Java Theory & Questions
    Replies: 12
    Last Post: May 6th, 2014, 07:33 AM
  4. pizza parlor orde
    By Mark Paynaganan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 20th, 2013, 04:44 AM
  5. java pizza program beginerr
    By nikki101 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 17th, 2013, 03:22 AM

Tags for this Thread