Re: Need help with my logic
- From: "TechGurl" <chanssr@xxxxxxxxx>
- Date: 8 Oct 2006 20:16:01 -0700
Lew thanks for the response. I corrected why you and Marcus suggest
however the program still doesn't calculate the total number of grades
that I imput. If I input 12 different grades I need for the result to
be Total number of grades: 12
What am I missing?
Lew wrote:
TechGurl wrote:
Error that I am getting:
Exception in thread "main" java.lang.Error: Unresolved compilation
problems:
numberOfA cannot be resolved //how I am to resolve this and the
others
numberOfB cannot be resolved
numberOfC cannot be resolved
numberOfD cannot be resolved
numberOfF cannot be resolved
at ExamScorer.main(ExamScorer.java:22)
public class ExamScorer
{
public static void main(String[] args)
{
System.out.println("Enter exam score: ");
int score;
char grade;
int sum;
int next;
String answer;
int countGrade = 0;
int countScore = 0;
Scanner keyboard = new Scanner(System.in);
{
These inner braces limit the scope of the variables declared within them.
System.out.println();
System.out.println("Enter all of the exam scores.");
sum=0;
int NumberOfA = 0;
int NumberOfB = 0;
int NumberOfC = 0;
int NumberOfD = 0;
int NumberOfF = 0;
next = keyboard.nextInt();
score = keyboard.nextInt();
grade = keyboard.next();
}
So outside them, the variables cannot be resolved.
sum = sum + next;
numberOfA++;
numberOfB++;
numberOfC++;
numberOfD++;
numberOfF++;
Remove the inner braces.
- Lew
.
- Follow-Ups:
- Re: Need help with my logic
- From: Patricia Shanahan
- Re: Need help with my logic
- References:
- Need help with my logic
- From: TechGurl
- Re: Need help with my logic
- From: Lew
- Need help with my logic
- Prev by Date: Re: connecting to a database
- Next by Date: Serialization and refactoring
- Previous by thread: Re: Need help with my logic
- Next by thread: Re: Need help with my logic
- Index(es):