Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error: cannot find symbol, help!

 
Glen Richard
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am running into the error of:

error: cannot find symbol

This is on each variable I have : mexicoPop, MexicoPopFin, usPop, Years


What have I done wrong? Such a beginner mistake I'm sure...

Also any critique on if this program is even gonna work will be great!!!


[HENRY: Fixed Code Tags]
 
Glen Richard
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't seem that's compatible with me since I don't use net-beans or eclipse or others listed. I'm using crimson editor. If you could please just let me know where my mistake lied at least, that would be much appreciated.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A warm welcome to the ranch Glen. Always use code tags to post code:



That's much better. Ain't it?

First things first. Are you new to Java?
 
Glen Richard
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah yes much much better. And how do the code tags work? I used the code button and filled in my code where it had "java" written.

Thanks for the welcome!

And yes I am new to Java and programming in general.

I've spent about 6 weeks learning and working with it, but seem to be missing some of the more basic logic.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. Well basics are the most essential part for learning any art, science, sport. I would advise you to start studying from this book. Devote some part of your time daily to understanding the concepts. Then if you have doubts, post them here. We are there for you. But no spoon-feeding. If we directly provide the answers to your queries, you won't be able to appreciate much of it.

Now the answer to your post:
It is a simple case of identifier mismatch. There is no mexicoPopFin in your code. So how will you use it. You ought to declare a variable before you can use it. Right? Same is the case with usPop etc..
 
Glen Richard
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I am actually currently studying java in and introduction to java course at university.

So would I declare it the same as my other variables?

I've now run into the error of the variable's already being defined.

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right: By starting the lines 18, 19 and 23 with "double" you're effectively re-declaring variables that have already been delcared in lines 11, 12 and 13. I suspect you merely want to assign to those variables - so remove the word "double" and see what happens.
 
Glen Richard
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was it! I can't believe I was overlooking that...thanks!

Now I'm faced with the issue of nothing printing out...

I tried moving the println to the if block but that did not change anything, still no output, but the program runs...
 
Campbell Ritchie
Sheriff
Pie
Posts: 49432
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glen Richard wrote: . . . I can't believe I was overlooking that... . . .
Lots of people make that mistake, so don’t worry about it.

What you are doing is using the != operator on floating‑point numbers. They are not precise (see no 20), so they never become exactly the same. So the loop never finishes. At least not until both populations reach ∞!
Try replacing the != operator with < or <=

And welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic