Search:

Type: Posts; User: Norm

Search: Search took 0.10 seconds.

  1. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Are you saying that only the variables: a,b,c,d will work and that the order of their values given in the ValVarPairs.txt file must be in this order: a,b,c,d?

    That should be documented in the...
  2. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Yes, that looks like the error the code will get.

    What assumptions does the code make about the variables' names and the order they are defined in the ValVarPairs.txt file?
  3. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Sorry, I don't know PHP.

    What happened when you changed the variables: c and d to x and y?
  4. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Try it and see what happens. Give x and y different values for clarity in showing test results.
    I think you will get a surprise.

    You'll need to get some help again to fix the code to make it...
  5. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Glad you got it working.

    --- Update ---

    What changes would you have to make to the program if the ValVarPairs.txt file were changed to contain these numbers-> a=100,b=5,x=10,y=13? Then the...
  6. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Is that the correct answer?
  7. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Does the program work for several different input expressions?
  8. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    That looks like the code does not find the values for the variable names in the expression but just uses the 4 values in the order that they were saved in the ValVarPairs.txt file.

    Try another...
  9. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    You didn't include the expression the program was to evalute???

    Given these values: a=100,b=5,c=10,d=13
    Looking at the printout and associating the contents of result with the values of the...
  10. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    That's what I am trying to do: show you how to debug the code and find the problem. To do that you need to add println statements, execute the program, copy the output and paste it here. Hopefully...
  11. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Yes, nothing that was done up to now has changed the program's results. The purpose of debugging a program is to find out why it is not generating the correct results. When that is understood, then...
  12. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    make sure all {s having a pairing }
    If the statements are properly formatted, it is a lot easier

    class AClass {
    void aMethod() {
    if(cond) {
    // do something
    ...
  13. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Please copy the full text of the compiler's error messages and paste it here.


    The {}s are still not correctly placed. Their positions should reflect the nesting level of the statements they...
  14. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Why is there a { on the next to last line?

    Check that all the }s have a pairing {.

    In general there should NOT be any code on the same line following a {.
    Also only put one statement per...
  15. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    What prints out when the program executes?

    The ids are not unique. I see res2 in two different places.
    Also there isn't a println() in the else

    Also there needs to be a println() outside the...
  16. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    There are 2 places where result gets assigned a value that don't have println() statements in the code in post#19 that did have them in post#15. You need to have println() statements after ALL the...
  17. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    You need to update the code and post the new version with the changed id strings and the added {}s following the if and else statements.
  18. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    What printed out?

    All the println()s have the same id String: "1res" so you won't be able to tell which println printed which line of output. Change them so that are all different: 1res, 2res,...
  19. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Don't give up on debugging the code. You will have to know how to debug for all the programs that you write.

    What did the debug println statements print out?
    Copy and paste what is printed out...
  20. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Put a println statement AFTER EVERY line where the variable result is assigned a value:

    result = someValue; // this statement assigns result a value
    System.out.println("1res="+result); //...
  21. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Start with printing out the value of the one variable: result and see what is printed. If that doesn't help, you can always add more println statements for other variables.
  22. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Here is a sample from your code:

    System.out.println(result);

    I'd change it to include an id string so you know which println's output you are seeing:

    ...
  23. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Time to start debugging to see where the code is going wrong. Add some println statements to print out the values of the variables as the code executes so you can see where the code is going wrong.
  24. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    What is the correct answer?
  25. Replies
    50
    Views
    3,531

    Re: Output of numbers are incorrect sometimes.

    Can you copy the contents of the command prompt window from when you execute the program that shows how the program is executed and what the program prints out when it executes?

    To copy the...
Results 1 to 25 of 25