Win a copy of Head First Android this week in the Android forum!

salvin francis

+ Follow
since Jan 12, 2009
salvin likes ...
Google Web Toolkit Eclipse IDE Java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt Green check

Recent posts by salvin francis

Fred, just wanted to add, it's been a decade since I have even touched C language.. But the variable scoping issues I saw in your code, would be pretty much the same in C or C++.
1 week ago

Campbell Ritchie wrote:Start from where you left off? Please explain a bit more, Salvin;

Open the text editor. Type in anything (even in multiple tabs). Close the editor. All the ones you mentioned will prompt you to save. See screenshots.
I love the ones that don't prompt and simply close. The next time you open them, they will start where you left off. Even if the machine was shutdown.
Some text editors which support this:
  • Windows: Notepadd++
  • Mac: BBedit
  • Linux: Notepadqq
  • I would love to discover some other ones.

    Campbell Ritchie wrote:it sounds as if I was mistaken not to use your favourite text editor.

    I was just trying to answer your previous question.

    Campbell Ritchie wrote:Does it support syntax highlighting for LaTeX?

    yes, it supports that. See screenshot

    Campbell Ritchie wrote:Would you like to add it somewhere; I think we have a text editors FAQ.

    I'll try and search around.
    1 week ago
    I tried all three of the above, they're good. Lightweight and cool. But.. There's two basic features that I look for in most text editors:
    1. Start from where I left off without saving
    2. Block select mode
    None of the three support 1.
    Block select has limited support in kate. e.g. Tab key does not work as expected.

    I think kate comes the closest, but I will still stick to notepadqq for now.
    1 week ago
    You could try notepadqq for linux
    1 week ago

    Fred Masen wrote:Salvin I use the proper way but Eclipse gave me so many errors while I was typing the code that I had to change it constantly. However you are correct about the bug but if you could demonstrate me how you can get this piece of code working properly without getting into classes and obtaining  the correct average age, I would deeply appreciate. Understand also that after a few hours of frustration I did not know what I was typing at the end

    I used notepad++ for a long while even when eclipse and netbeans were getting popular. Using a simple text editor will help you learn faster. Once you've learned the language well, then switching to an IDE would help you write larger programs.
    2 weeks ago
    Although you mentioned a couple of times that you wrote the same code as the book, it was not true. Please understand that in the world of programming, a single line change could alter the complete program. It's no longer the book's code, now that it's changed, it's your code !!
    2 weeks ago
    I just wanted to circle back to your previous code to explain the bug:

    Here are issues:
    1. "total" is set to 0 at the starting of the code and then used in the loop. For every iteration of the loop it remembers it's last value. This is the root cause of the issue you were facing.
    Note that in your original code, you had written this line inside the for loop:
    In the later code, you removed it. This is the bug that was causing a wrong output for scores. I tried to point it out, but we could not reach common ground here
    2. If you're using "total" for scores, why are you using it for calculating age total as well ? The value from scores should be unrelated to age feature. There's also a spelling mistake where you are modifying the value of "average" instead of "averageAge".

    For 2. Campbell suggested to use meaningful variable names. This would have highlighted the wrong code.
    As Piet suggested, you can move to an Object oriented approach as well. But first, I suggest understanding variable scopes and how values are retained or forgotten. You could declare "total" within the for loop as well.
    2 weeks ago
    I have asked a couple of questions above, I haven't received answers for any of them
    2 weeks ago

    I wrote:...

    50 is wrong. There's a reason why this is happening.

    Here's the answer to this. The average should have been

    But the behavior of the code is:

    Do you know what this 15 is ? Campbell's post has more clues about it.
    2 weeks ago

    Fred Masen wrote:Francis what you have posted is what the book of Gaddis starting out Java example program was giving me and I understand it perfectly fine. In order to improve my coding skills I tried to included the age feature but it does not work because as I said it seems to be missing a for loop for the age feature. .

    I understand it, but before adding "age", have a look at scores. The scores code is not working as well. In your code, the output comes to :

    50 is wrong. There's a reason why this is happening.
    2 weeks ago
    hint: it's the variable called "total"
    2 weeks ago
    Perfect !!
    Now, I've removed the age feature entirely from your code:


    I see that in the first round, it behaves correctly. The second time, score average is off. Are you able to spot why ?
    2 weeks ago
    Let's break the problem into smaller parts:


    I would expect the average score to be (20+30) / 2 = 25.


    I would expect the average score to be (40+50)/2 = 45

    Do you agree ?
    2 weeks ago
    I agree, but right now, the issue has nothing to do with java.
    Let's communicate effectively, you're stuck at a point, we're trying to help you out.
    2 weeks ago
    As I suggested, leave the code aside.

    you posted:

    Is this your Expected output ?
    2 weeks ago