ExamNotes.net

General discussions => Programming Forum => Topic started by: Chanss_R on October 08, 2006, 03:54:09 PM



Title: I need help with my logic.
Post by: Chanss_R on October 08, 2006, 03:54:09 PM
I am trying to get this program to return the total number of grades entered as well as the total number of A's, B's C'a etc.
I am new at this and just needs some guidance.




Error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
   Char cannot be resolved to a type
   numberOfA cannot be resolved
   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);
               
               {
                   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();
                 
               }
                      sum = sum + next;
                       numberOfA++;
                      numberOfB++;
                      numberOfC++;
                      numberOfD++;
                      numberOfF++;
                      next = keyboard.nextInt();
                   
                                                   
               if (score >= 90)
                   grade = 'A';
               else if (score >= 80)
                   grade = 'B';
               else if (score >= 70)
                   grade  = 'C';
               else if (score >= 60)
                   grade = 'D';
               else
                  grade = 'F';


Title: I need help with my logic.
Post by: ashyour on October 16, 2006, 01:39:41 PM
{  //remove
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();

}//remove




Remove the curly braces which are indicated above and your problem will be solved.
these curly braces are making your veriables local so they are not accessible out side the curly braces.
for further support visit
http://www.braindumpindia.com