Results 1 to 2 of 2

Thread: Cannot find symbol error?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    17

    Cannot find symbol error?

    The program is just a simple one to print grades using only methods.

    the problem is Im trying to use a returned value in another method but the compiler keeps telling me it cannot find the symbol "mark". the problem areas are marked in blue.
    Im basically trying to input a value into the keyboard and then use it in another method.

    any help would be great.
    public static void main(String[] args)
    {
    printTitle();
    enterMark();
    gradeCalculator(mark);
    printGrade();

    }

    public static void printTitle()
    {
    System.out.println("Grade Classifier");
    System.out.println("****************");
    }

    public static int enterMark()
    {
    Scanner in = new Scanner(System.in);
    System.out.print("Enter grade ");
    int mark = in.nextInt();
    return mark;
    }

    public static String gradeCalculator(int grade)
    {
    String gradeAchieved = "";

    if(grade >= 70 && grade <= 100)
    {
    gradeAchieved = "Grade A Pass";
    }

    else if(grade >= 60 && grade <= 69)
    {
    gradeAchieved = "Grade B Pass";
    }

    else if(grade >= 50 && grade <= 59)
    {
    gradeAchieved = "Grade C Pass";
    }

    else if(grade >= 40 && grade <= 49)
    {
    gradeAchieved = "Grade D Pass";
    }

    else
    {
    gradeAchieved = "Grade F Fail";
    }

    return gradeAchieved;
    }



    public static void printGrade()
    {
    System.out.println("Congrtulations, you are awarded a ");

    //Incomplete
    }

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Cannot find symbol error?

    mark is local to the enterMark function, so you can't reference it outside that function, it doesn't exist.
    You're returning the value from the function, so either assign it to a variable, or use the return directly.
    Code:
    public static void main(String[] args)
    {
    printTitle();
    int mark = enterMark();
    gradeCalculator(mark);
    printGrade();
    
    }
    
    // or
    
    public static void main(String[] args)
    {
    printTitle();
    gradeCalculator(enterMark());
    printGrade();
    
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width