0

So I’ve bolded were the errors are happening but I don’t understand why they are happening. It doesn’t make sense to me.

    for(int i = 1; i < Array.getLength(purchases);i++)
    {
        System.out.print("\n");
        System.out.print("Enter a price for item #"+i+": $");
        double temp3=input.nextDouble();
        double price=temp3;

            if(price=>0) **<==it wont let me have both = and >**
            {
                total=total+price;
                double temp1=total*100;
                int temp2=(int)temp1;
                total=temp2/100.0;
        System.out.print("That was $"+price+". Your total is $"+total);
            }
       else(price==0) **<=="The left-hand side of an assignment must be a variable"**
            {

            }
    }
1
  • You cannot use bold with code formatting, now the code is messed up by formatting Commented Nov 18, 2012 at 19:28

3 Answers 3

2
if(price=>0)

This should be: -

if(price >= 0)

Note the order of > and =. > comes first.

And also: - else(price==0) should just be else, you don't need to add a condition in your else.

Sign up to request clarification or add additional context in comments.

2 Comments

@TylerDManary.. haha :) Well, certainly, given that you are doing these kinds of errors.
i wonder how many more times i would have over looked that if i had not of asked
1

your greater than or equal to ordering is wrong.

if(price=>0)

should be

if(price>=0)

the correct ordering is to use >=

 else(price==0)

should be

 else if(price<0) //should be less than zero , because you are already checking if price is >=0 in your if.

or just else would suffice

nested if-else syntax:

  if(somecond){

   }
   else if(somecond){
    }
   else{ // you don't mention any condition for else, as it would be the last condition.

    }

7 Comments

Note that, your else if condition is already covered in your if. Just else would work.
@GanGnaM.. Well, in that case, your else if will never get executed. It tests for condition ==, and your if already has a condition >= which will itself check for ==.
So, either it should be else if(price < 0) which seems useless, so just else.
@RohitJain i just realised, else should check if price is lessthan 0 .as he's already checking in if price >=0. :P
@RohitJain dude, if you dont mind. its 1:00 AM in india i suppose, go to bed :P
|
0

In java, "greater than or equal to" is >=. Also, for the second error, you should have "else if", not just "else."

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.