• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with 'missing symbol' error  RSS feed

 
Nafisa Faruque
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am absolutely new to programming languages and Java. So I have an assignment in which I need help.
There is an error in line: 13 which says:
Error: cannot find symbol
symbol: variable count

Also posting my assignment question for better understanding:
Task 2:
Write a java program that reads five numbers from the user, and prints their average.

Here's what I did:

 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't increment by two using ++++. Use count += 2;
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please UseCodeTags (← click). I've added them for you this time.

It will also help if you format your code consistently, that is, make sure all the braces line up.
 
Nafisa Faruque
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:You can't increment by two using ++++. Use count += 2;


Thanks for your response! I tried fixing it. Still getting the same error in line 14 which says:
Error: cannot find symbol
symbol: variable count

 
Charles D. Ward
Ranch Hand
Posts: 99
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You declared the count variable inside the for loop, so when the loop is over count doesn't exist anymore.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Nafisa,

you get this error because 'count' is a local variable in the loop. See these lines:

As soon as Java gets to the line 'int average = 0;' the count variable is out of
scope. A simple remedy is to put 'count' just before the loop, like


Then 'count' will still be in scope after the loop.

Greetz,
Piet
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!