Exercise – Implement code branches using selection statements

In this exercise, you’ll develop the code that automatically assigns a student’s letter grade based on their final numeric score and you’ll update the application so that extra credit project scores are factored into the student’s final grade. You will begin by writing an if-elseif-else construct that can be used to evaluate the student’s numeric score and assign the letter grade. Next, you’ll examine the application requirements related to extra credit work, and then work your way through the required code updates. The detailed tasks that you’ll complete during this exercise are:

  1. Develop an if-elseif-else construct that evaluates the student’s score to assign a letter grade. The expression that’s evaluated compares the student’s numeric score with a range of scores taken from a grading chart provided by the teacher.
  2. Integrate extra credit scores into each student’s scores array, and then update the code that’s used to calculate the student’s numeric score. The foreach that’s used to sum the student scores will be updated to include an if statement that branches the code. The exam scores will be applied to the sum in one branch, and the extra credit scores in the other branch.

 Important

You need to have completed this module’s previous Exercise, “Create arrays and foreach loops”, before you begin this Exercise.

Assign letter grades using an if-elseif-else construct

In this task, you’ll develop an if-elseif-else structure that can be used to assign letter grades based on a calculated numeric score.

  1. Ensure that you have the Program.cs file open in the Visual Studio Code Editor.
  2. Create a blank code line below the line used to declare studentScores array.
  3. To create a string variable that can be used to hold the student’s letter grade, enter the following code:C#Copystring currentStudentLetterGrade = "";
  4. Scroll down to the bottom of the Program.cs file.
  5. Add a blank code line below the line that assigns a calculated value to currentStudentGrade.
  6. Take a minute to consider the grading chart that shows the letter grade corresponding to numeric scores.

microsoft sharepoint certification training courses malaysia

Leave a Reply

Your email address will not be published. Required fields are marked *