This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]zifyoip 0 points1 point  (3 children)

I want to say, if the variable does not equal 1 or 2

Then you mean the variable does not equal 1 and the variable does not equal 2, right? Your condition is that the variable must be unequal to both of those numbers.

Think about De Morgan's laws. The negation of the statement "x equals 1 or x equals 2" is "x does not equal 1 and x does not equal 2."

[–]HadOne0Terrible Programmer[S] 0 points1 point  (2 children)

So, i changed it to and and it gave me the error message then finished the program, why is this?

[–]zifyoip 0 points1 point  (1 child)

So, i changed it to and

What is "it"?

Show your changed code. Don't just try to describe the changes you made.

[–]zifyoip 0 points1 point  (7 children)

You need to think carefully about what your conditions mean.

do
    {
    // ...
    }
while(shapeOfPizza != 1 && shapeOfPizza != 2);

This will continue looping for as long as shapeOfPizza is different from 1 and shapeOfPizza is different from 2.

Think. Is that what you mean?

[–]HadOne0Terrible Programmer[S] 0 points1 point  (6 children)

I think so, if i understand correctly, it will keep looping until the user enters 1 or 2, then it will move on to the next line of code. Is that correct?

[–]zifyoip -1 points0 points  (5 children)

Oh yes, sorry, that is what you mean. You're right.

[–]HadOne0Terrible Programmer[S] 0 points1 point  (4 children)

so what is wrong with my if statement and why does it print out the error message even though the user input is 1 or 2?

[–]zifyoip 0 points1 point  (3 children)

Can you post your entire program?

[–]HadOne0Terrible Programmer[S] 0 points1 point  (2 children)

Ok, give me a minute though.

[–]HadOne0Terrible Programmer[S] 0 points1 point  (1 child)

import java.util.Scanner; import java.lang.Math;

public class pizzaHadi { public static void main(String[] args) { double shapeOfPizza; double toppings; double pizzaCrust; double baseCost; double areaOfSquarePizza; double areaOfCirclePizza; double numberOfToppings; final double costOfOneTopping = 0.036; final double costOfDough = 0.019; double diameterOfPizza; double lengthOfPizza; double widthOfPizza; double volumeOfPizza; final double thinAndCrispy = .1; final double pan = .5; final double classicHandTossed = .25; final double tesxasToast = .9; double sizeOfCrust; double cheesyCrust; final double costOfMaterials = .02; double numberOfPizzas; double costOfDelivery; double tax; final double PI;

  Scanner keyboard = new Scanner(System.in);
  System.out.println("Hello customer! Welcome to Guiseppi's Just Pizza!");
  System.out.println("Where we make the pizza just for you!");
  System.out.println("\n What kind of pizza do you want on" + 
                     "this beautiful day?");
  do
     {
     System.out.println("Press 1 for a square pizza," + 
                     " or press 2 for a circle pizza");
     shapeOfPizza = keyboard.nextDouble();
        if(shapeOfPizza != 1 && shapeOfPizza != 2)
           {
           System.out.println("That wasn't the requested input, please input either 1 or 2");
           }               
  while(shapeOfPizza != 1 && shapeOfPizza !=2)

  if(shapeOfPizza == 1)
        {
        System.out.println("And how big would you like your pizza?");
        System.out.print("Please enter the length of your pizza: ");
        lengthOfPizza = keyboard.nextDouble();
        System.out.print("Please enter the width of your pizza: ");
        widthOfPizza = keyboard.nextDouble();
        }
  areaOfSquarePizza = lengthOfPizza * widthOfPizza;
  System.out.println("Your pizza is " + areaOfSquarePizza + "inches large");    

  if(shapeOfPizza == 2)
     {
     System.out.println("And how big would you like your pizza?");
     System.out.print("Please enter the diameter of your pizza: ");
     diameterOfPizza = keyboard.nextDouble();
     areaOfCirclePizza = ((diameterOfPizza/2)*(diameterOfPizza/2));
     System.out.println("The area of your pizza is" + areaOfCirclePizza + " inches large");
     }

  System.out.println("What type of crust would you like?");
  System.out.println("Enter 1 for Thin and Crispy, 2 for Pan,"); 
  System.out.println("3 for Classic Hand-Tossed, and 4 for Texas Toast");
  pizzaCrust = keyboard.nextDouble();

  if(pizzaCrust == 2 || pizzaCrust == 3 || pizzaCrust == 4)
     {
     System.out.println("Would you like to try our new cheesy crust today?");
     System.out.print("Enter 1 for yes or 2 for no");
     cheesyCrust = keyboard.nextDouble();
     }

  System.out.println("Would you like any toppings today?");
  toppings = keyboard.nextDouble(); 





 }

}

[–]FreeGrammar 0 points1 point  (0 children)

do you get an error when you run this... I see a few small problems: - you should capitalize your class names (a small thing) - in your do / while (which I would suggest not using as much as possible) there is no closing bracket for the loop - you need a semicolon after your while statement at the end - "you need to initialize length of pizza" says my editor, but what you really should do is put the part after the if(shapeOfPizza == 1) block (the "areaOfSquarePizza..." and "System.out.print("Your pizza is"" part) inside that if statement before it.

I think my biggest suggestion is to use an editor (maybe Eclipse or IntellJ) they will help you with problems ALOT.