16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 46 41 42 43 44 45 O references static void Main() { // array declaration int[] testScore = new int [8]; //variable declaration float avg, sum = 0; // get user input Console.WriteLine("Enter the test score of eight student"); for (int i = 0; i < 8; i++) { } ¡ TestScoreList.Program { int j = 0; testScore[j] = Convert.ToInt32(Console.ReadLine()); sum sum + testScore[]; // cakculate average avg= sum / 8; // display the result for (int i = 0; i < 8; i++) { } int i = 0; Console.Write("Test #" +1+""+ testScore[i] + "From average: "+(double) (testScore[i]-avg) + "\n"); }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

C# Question. Where are the errors coming from in my code? I tried different ways but no luck. Help would be appreciated of input and output!

### Code Sample
```csharp
static void Main()
{
    // array declaration
    int[] testScore = new int[8];

    // variable declaration
    float sum, avg = 0;
    sum = 0;

    // user input
    Console.WriteLine("Enter the test score of eight students");

    for (int i = 0; i < 8; i++)
    {
        int j = 0;
        testScore[j] = Convert.ToInt32(Console.ReadLine());
        sum = sum + testScore[j];
    }

    // calculate average
    avg = sum / 8;

    for (int i = 0; i < 8; i++)
    {
        int i = 0;
        Console.Write("Test #" + i + ": " + testScore[i] + " from average " + ((double)(testScore[i] - avg)) + "\n");
    }
}
```

### Error List Explanation
- **CS1044**: Syntax error, value expected.
  - **Description**: A local or parameter named 'i' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter.
  - **Project**: TestScoreList
  - **File**: Program.cs
  - **Lines**: 32, 37

### Analysis
The code provided is a C# program intended to calculate and display the difference of test scores of eight students from their average score. However, there are a few logical and syntax errors present:

#### Issues Identified:
1. The variable `j` is reinitialized inside the loop, causing incorrect indexing of the `testScore` array. The code should instead use the loop variable `i` for indexing.
   
2. The second declaration of `int i = 0;` inside the second loop is incorrect as it re-declares `i` inside the scope of the existing loop's variable i, causing a conflict. Each loop should have distinct variable names, or the inner loop should reference the outer loop's iteration variable directly, if required.

3. The comments are correctly placed to explain each segment of the code, but the correct usage and logic within loops must be ensured for accurate computation.

#### Corrected Code:
```csharp
static void Main()
{
    // array declaration
    int[] testScore = new int[8];

    // variable
Transcribed Image Text:### Code Sample ```csharp static void Main() { // array declaration int[] testScore = new int[8]; // variable declaration float sum, avg = 0; sum = 0; // user input Console.WriteLine("Enter the test score of eight students"); for (int i = 0; i < 8; i++) { int j = 0; testScore[j] = Convert.ToInt32(Console.ReadLine()); sum = sum + testScore[j]; } // calculate average avg = sum / 8; for (int i = 0; i < 8; i++) { int i = 0; Console.Write("Test #" + i + ": " + testScore[i] + " from average " + ((double)(testScore[i] - avg)) + "\n"); } } ``` ### Error List Explanation - **CS1044**: Syntax error, value expected. - **Description**: A local or parameter named 'i' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter. - **Project**: TestScoreList - **File**: Program.cs - **Lines**: 32, 37 ### Analysis The code provided is a C# program intended to calculate and display the difference of test scores of eight students from their average score. However, there are a few logical and syntax errors present: #### Issues Identified: 1. The variable `j` is reinitialized inside the loop, causing incorrect indexing of the `testScore` array. The code should instead use the loop variable `i` for indexing. 2. The second declaration of `int i = 0;` inside the second loop is incorrect as it re-declares `i` inside the scope of the existing loop's variable i, causing a conflict. Each loop should have distinct variable names, or the inner loop should reference the outer loop's iteration variable directly, if required. 3. The comments are correctly placed to explain each segment of the code, but the correct usage and logic within loops must be ensured for accurate computation. #### Corrected Code: ```csharp static void Main() { // array declaration int[] testScore = new int[8]; // variable
## Chapter 6: Using Arrays

### 2. TestScoreList Program
Write a program named **TestScoreList** that accepts eight `int` values representing student test scores. Display each of the values along with a message that indicates how far it is from the average.

### 3. TemperaturesComparison Program
Write a program named **TemperaturesComparison** that allows a user to input five daily Fahrenheit temperatures that must range from -30 to 130. If a temperature is out of range, require the user to reenter it. If no temperature is lower than any previous one, display a message "Getting warmer." If every temperature is lower than the previous one, display a message "Getting cooler." If the temperatures are not entered in either ascending or descending order, display a message "It's a mixed bag." Finally, display the temperatures in the order they were entered, and then display the average of the temperatures.

### 4. CheckZips Program
Write a program named **CheckZips** that is used by a package delivery service to check delivery areas. The program contains an array that holds the 10 zip codes of areas to which the company makes deliveries. Prompt a user to enter a zip code and display a message indicating whether the zip code is in the company's delivery area.

### 5. DeliveryCharges Program
Write a program called **DeliveryCharges** for the package delivery service in Exercise 4. The program should again use an array that holds the 10 zip codes of areas to which the company makes deliveries. Create a parallel array containing 10 delivery charges, one for each zip code. Prompt a user to enter a zip code, and then display either a message indicating the price of delivery to that zip code or a message indicating that the company does not deliver to the requested zip code.

### 6. What-A-While Phone Company Program
The What-A-While phone company provides service to six area codes and charges per-minute rates for phone calls shown in Figure 6-25. Write a program named **What-A-While** that stores the area codes and rates in parallel arrays and allows a user to enter an area code and the length of time for a call in minutes, and then display the total cost of the call.
Transcribed Image Text:## Chapter 6: Using Arrays ### 2. TestScoreList Program Write a program named **TestScoreList** that accepts eight `int` values representing student test scores. Display each of the values along with a message that indicates how far it is from the average. ### 3. TemperaturesComparison Program Write a program named **TemperaturesComparison** that allows a user to input five daily Fahrenheit temperatures that must range from -30 to 130. If a temperature is out of range, require the user to reenter it. If no temperature is lower than any previous one, display a message "Getting warmer." If every temperature is lower than the previous one, display a message "Getting cooler." If the temperatures are not entered in either ascending or descending order, display a message "It's a mixed bag." Finally, display the temperatures in the order they were entered, and then display the average of the temperatures. ### 4. CheckZips Program Write a program named **CheckZips** that is used by a package delivery service to check delivery areas. The program contains an array that holds the 10 zip codes of areas to which the company makes deliveries. Prompt a user to enter a zip code and display a message indicating whether the zip code is in the company's delivery area. ### 5. DeliveryCharges Program Write a program called **DeliveryCharges** for the package delivery service in Exercise 4. The program should again use an array that holds the 10 zip codes of areas to which the company makes deliveries. Create a parallel array containing 10 delivery charges, one for each zip code. Prompt a user to enter a zip code, and then display either a message indicating the price of delivery to that zip code or a message indicating that the company does not deliver to the requested zip code. ### 6. What-A-While Phone Company Program The What-A-While phone company provides service to six area codes and charges per-minute rates for phone calls shown in Figure 6-25. Write a program named **What-A-While** that stores the area codes and rates in parallel arrays and allows a user to enter an area code and the length of time for a call in minutes, and then display the total cost of the call.
Expert Solution
Step 1

There are two Errors in your code 

On line Number 32

You have used sum = sum += testscore[];

replace code with sum += testscore[];

 

 

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY