none
Not All Code paths return a value (Beginner) RRS feed

  • Question

  • Hi Everyone,

    I'm trying to create an if else statement to display the appropriate grade based on the exam score average. Error is found in Line 116.

    using System;


    namespace ExamScores
    {
        public class ExamScoresApp
        {
            /*With this program we will be calculating an average off of 5
             * exam scores and then giving the student their average and grade in the class
             * *****************************************/

            private string studentName;
            private int studentID;
            private int examScore1;
            private int examScore2;
            private int examScore3;
            private int examScore4;
            private int examScore5;
            private int average;
            
            //default constructor
            public ExamScoresApp()
            {

            }
            public ExamScoresApp(int sID, string name, int s1, int s2, int s3, int s4, int s5)
            {
                studentID = sID;
                studentName = name;
                examScore1 = s1;
                examScore2 = s2;
                examScore3 = s3;
                examScore4 = s4;
                examScore5 = s5;

            }
            //Properties
            public string StudentName
            {
                get
                {
                    return studentName;
                }
                set
                {
                    studentName = value;
                }
            }
            public int StudentID
            {
                get
                {
                    return studentID;
                }
                set
                {
                    studentID = value;
                }
            }
            public int ExamScore1
            {
                get
                {
                    return examScore1;
                }
                set
                {
                    examScore1 = value;
                }
            }
            public int ExamScore2
            {
                get
                {
                    return examScore2;
                }
                set
                {
                    examScore2 = value;
                }
            }
            public int ExamScore3
            {
                get
                {
                    return examScore3;
                }
                set
                {
                    examScore3 = value;
                }
            }
            public int ExamScore4
            {
                get
                {
                    return examScore4;
                }
                set
                {
                    examScore4 = value;
                }
            }
            public int ExamScore5
            {
                get
                {
                    return examScore5;
                }
                set
                {
                    examScore5 = value;
                }
            
            }
            public int DetermineGrade()
            {
                average = (examScore1 + examScore2 + examScore3 + examScore4 + examScore5) / 5;
                      
                if (average > 89)
                {
                    Console.Write("A");
                }
                else if (average > 79)
                {
                    Console.Write("B");
                }
                else if (average > 69)
                {
                    Console.Write("C");
                }
                else if (average > 59)
                {
                    Console.Write("D");
                }
                else
                {
                    Console.Write("F");
                }
                
            }
                    public override string ToString()
            {
                return "Student Name: " + studentName
                    + "\nStudent ID: " + studentID
                    + "\nExam Score 1: " + examScore1
                    + "\nExam Score 2: " + examScore2
                    + "\nExam Score 3: " + examScore3
                    + "\nExam Score 4: " + examScore4
                    + "\nExam Score 5: " + examScore5
                    + "\nExam Average; " + average;
            }
        }
    }

    Any help would be much appreciated.

    Thanks,

    Von Doss

    Saturday, July 27, 2013 7:35 PM

Answers

  • Look at your method signature below, you're guranteeing that you'll return a result of int. 

    public int DetermineGrade()
     

    However, there's no return statement anywhere. If you add the line below at the end of the method you won't get the error any more.

    return average;

    Saturday, July 27, 2013 8:19 PM

All replies

  • Look at your method signature below, you're guranteeing that you'll return a result of int. 

    public int DetermineGrade()
     

    However, there's no return statement anywhere. If you add the line below at the end of the method you won't get the error any more.

    return average;

    Saturday, July 27, 2013 8:19 PM
  • Thank you. I made that changed and it help me identify some other formatting errors in my code as well.
    Saturday, July 27, 2013 9:57 PM
  • Look at your method signature below, you're guranteeing that you'll return a result of int. 

    public int DetermineGrade()
     

    However, there's no return statement anywhere. If you add the line below at the end of the method you won't get the error any more.

    return average;

    wow...nice reply ...worked for me too.............Thank you
    Friday, June 20, 2014 9:46 PM