Exercise – Construct a nested loop structure for student grade calculations

In this exercise, you’ll add a string array to hold the student names, and then implement a nested foreach structure that iterates through the student names in an outer loop and student scores in the inner loop. You’ll begin by constructing the studentNames array and a foreach loop that iterates through the array elements. Next, you’ll move the code that’s used to calculate Sophia’s grades into the code block of the “names” loop. Finally, you’ll implement the code logic that uses the student’s name to access their scores array, calculate their average score, and write their grade to the console. The detailed tasks that you’ll complete during this exercise are:

  1. Create names array: Create a student names array.
  2. Create outer loop: Create a foreach loop that iterates through the student names.
  3. Develop outer loop code block: Relocate the code that calculates and reports Sophia’s score, placing it in the code block of the “names” loop.
  4. Update calculations and reporting: Update the code that performs student score calculations using a new scores array.

 Important

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

Create a student names array and outer foreach loop

In this task, you’ll create a student names array and a foreach loop that iterates through the student names.

  1. Ensure that you have the Program.cs file open in the Visual Studio Code Editor.
  2. Scroll to the top of your code file, and then locate the code lines that are used to declare the scores arrays.
  3. Create a blank code line below the declaration of the scores arrays.Your blank code line should be located between the lines used to declare the scores arrays and the line used to declare sophiaSum.

vmware certification training courses malaysia

Leave a Reply

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