Results 1 to 3 of 3
  1. #1
    jhern87 is offline Member
    Join Date
    Oct 2013
    Rep Power

    Default Having Trouble Getting Formula in Code to Compute Correctly

    Hi everyone, I'm taking an entry level software programming class and am having to write a fairly simple code but can't seem to get it to compute right. This is what my code looks like as of now.

    Welcome to Cheap Beds, Inc.! Please answer the following questions so we know how much to charge our customers.

    <script type="text/javascript">

    var Origprice;

    Origprice = prompt('Enter the Original Price of the bed');

    var DelivFee;

    DelivFee = prompt ('How much are we charging for delivery?');

    var credit;

    credit = prompt ('How much are we crediting for their old unit?');

    var Newcost;

    Newcost = (parseInt(Origprice) + parseInt(DelivFee));

    var Finalcost;

    Finalcost = (parseInt(Newcost) - parseInt(DelivFee));

    alert("The bed that was chosen will cost" + Finalcost + " Including delivery fee and trade-in credit for their old bed");



    The cost of the bed that I'm entering is 100, shipping is 20 and credit is 5 but at the end it's saying that the price is 100? Does anyone know how I can fix this?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Having Trouble Getting Formula in Code to Compute Correctly

    This is a Java forum, not Javascript.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Rep Power

    Default Re: Having Trouble Getting Formula in Code to Compute Correctly

    Stackoverflow is a good place to ask for generic programming help.

    Needless to say, take a look again at the calculations you are doing because of course the problem is there. Replace the variables you are using with the actual numbers and write out on a piece of paper what the result is going to be. The problem should dawn on you quite quickly that way.
    Last edited by gimbal2; 10-23-2013 at 09:19 AM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Distance Formula and Random numbers code
    By granslime in forum New To Java
    Replies: 10
    Last Post: 09-26-2013, 07:27 PM
  2. Replies: 3
    Last Post: 04-01-2013, 05:40 AM
  3. Did I comment this code correctly?
    By Vinx in forum New To Java
    Replies: 5
    Last Post: 06-17-2012, 01:50 AM
  4. Replies: 18
    Last Post: 08-09-2011, 08:08 AM
  5. Code completion not updating correctly
    By kspn in forum NetBeans
    Replies: 1
    Last Post: 02-22-2011, 11:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts