4 Replies - 70 Views - Last Post: 07 February 2012 - 07:57 PM Rate Topic: -----

Topic Sponsor:

#1 mizbrowneyez34  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-January 12

can you tell me what im doing wrong, cant get the code to calculate

Posted 07 February 2012 - 07:23 PM

// DebugWeek2Four
// Adds your lunch bill
// Burger and hot dog are $2.59
// Grilled cheese and fish are $1.99
// Fries are 89 cents
import javax.swing.*;
public class FixDebugFive1NDH
{
   public static void main(String args[]) throws Exception
   {
      String usersChoiceString;
      int usersChoice;
      double bill = 0.0;
      
      usersChoiceString = JOptionPane.showInputDialog(null,
         "Order please\n1 - Burger \n2 - Hotdog" +
    		  "\n3 - Grilled cheese \n4 - Fish sandwich");
      usersChoice= Integer.parseInt(usersChoiceString);
      if(usersChoice == 1 | usersChoice == 2)
         bill += 2.59;
         else;
         bill += 1.99;
      usersChoiceString = JOptionPane.showInputDialog(null,
          "Fries with that?\n1 - Yes\n2 - No");
      usersChoice = Integer.parseInt(usersChoiceString);
      if(usersChoice == 1)
          bill += 0.89;
      JOptionPane.showMessageDialog(null,"Bill is " + bill);
   }
}

This post has been edited by smohd: 07 February 2012 - 07:52 PM
Reason for edit:: Code tags added. Please use [code] tags when posting codes


Is This A Good Question/Topic? 0
  • +

Replies To: can you tell me what im doing wrong, cant get the code to calculate

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 640
  • View blog
  • Posts: 4,287
  • Joined: 24-October 08

Re: can you tell me what im doing wrong, cant get the code to calculate

Posted 07 February 2012 - 07:30 PM

can you please enclose your code between code tags, and describe the problem you're facing :)
Was This Post Helpful? 0
  • +
  • -

#3 jimmyo88  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 126
  • Joined: 27-February 11

Re: can you tell me what im doing wrong, cant get the code to calculate

Posted 07 February 2012 - 07:34 PM

change your code on this line.

if(usersChoice == 1 | usersChoice == 2)
 bill += 2.59;
 else if (usersChoice == 3 | usersChoice == 4)
 bill += 1.99;



That should see it working :)
Was This Post Helpful? 0
  • +
  • -

#4 ianian112  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 106
  • View blog
  • Posts: 359
  • Joined: 28-November 09

Re: can you tell me what im doing wrong, cant get the code to calculate

Posted 07 February 2012 - 07:39 PM

View Postjimmyo88, on 07 February 2012 - 07:34 PM, said:

change your code on this line.

if(usersChoice == 1 | usersChoice == 2)
 bill += 2.59;
 else if (usersChoice == 3 | usersChoice == 4)
 bill += 1.99;



That should see it working :)

| is a bitwise operator that compares the bits, you should change it to ||
Was This Post Helpful? 0
  • +
  • -

#5 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1644
  • View blog
  • Posts: 4,126
  • Joined: 14-March 10

Re: can you tell me what im doing wrong, cant get the code to calculate

Posted 07 February 2012 - 07:57 PM

It will be better if you tell us what problem you have, if you are getting any error message please post the exact error or if you have output which is not what you expected, then tell us what is it and what you were expecting instead. Dont expect us to test your code without knowing what you are trying to do.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1