any amount of ed. Design the logic for a program that allows a user to enter 20 numbers, then displays each number and its difference from the numeric average of the numbers entered. Modify the program in Exergia

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I had to answer question number 2 part a, although we're making it for up to 5 numbers instead. I wanted to know where my mistake occurred because this program doesn't function correct(Visual Basic).

Below is the transcription of the text from the image, adapted for an educational website:

---

### Understanding Basic Loops in Visual Basic

This example demonstrates a simple Visual Basic program designed to read five numbers, calculate their sum and average, and then display each number along with its difference from the average.

```vb
Module Module1
    Sub Main()
        Dim Size As Integer = 5
        Dim Sum As Double = 0
        Dim Average As Double = 0
        Dim TheNumbers(Size) As Double

        Console.WriteLine("Input 5 numbers total")
        For index = 0 To 4 Step 1
            Console.WriteLine("Enter a number")
            TheNumbers(index) = Console.ReadLine()
            Sum = Sum + TheNumbers(index)
        Next

        Average = Sum / Size
        For index = 0 To 4
            Console.WriteLine("The number is " & TheNumbers(index))
            Console.WriteLine("The difference from the average is " & TheNumbers(index) - Average)
        Next
    End Sub
End Module
```

#### Program Explanation

- **Variables:**
  - `Size`: Specifies the total number of inputs, set to 5.
  - `Sum`: Used to store the cumulative sum of the numbers entered.
  - `Average`: Stores the average of the entered numbers.
  - `TheNumbers`: An array holding the inputted numbers.

- **Flow of the Program:**
  1. **Input Phase:**
     - The program prompts the user to input five numbers.
     - It reads each number and adds it to `Sum`.
  2. **Calculating Average:**
     - Once all numbers are inputted, it calculates the average by dividing `Sum` by `Size`.
  3. **Output Phase:**
     - The program iterates through the array to print each number and its difference from the average.

This program provides a basic understanding of loops and arrays in Visual Basic, important for handling repetitive tasks and data storage.
Transcribed Image Text:Below is the transcription of the text from the image, adapted for an educational website: --- ### Understanding Basic Loops in Visual Basic This example demonstrates a simple Visual Basic program designed to read five numbers, calculate their sum and average, and then display each number along with its difference from the average. ```vb Module Module1 Sub Main() Dim Size As Integer = 5 Dim Sum As Double = 0 Dim Average As Double = 0 Dim TheNumbers(Size) As Double Console.WriteLine("Input 5 numbers total") For index = 0 To 4 Step 1 Console.WriteLine("Enter a number") TheNumbers(index) = Console.ReadLine() Sum = Sum + TheNumbers(index) Next Average = Sum / Size For index = 0 To 4 Console.WriteLine("The number is " & TheNumbers(index)) Console.WriteLine("The difference from the average is " & TheNumbers(index) - Average) Next End Sub End Module ``` #### Program Explanation - **Variables:** - `Size`: Specifies the total number of inputs, set to 5. - `Sum`: Used to store the cumulative sum of the numbers entered. - `Average`: Stores the average of the entered numbers. - `TheNumbers`: An array holding the inputted numbers. - **Flow of the Program:** 1. **Input Phase:** - The program prompts the user to input five numbers. - It reads each number and adds it to `Sum`. 2. **Calculating Average:** - Once all numbers are inputted, it calculates the average by dividing `Sum` by `Size`. 3. **Output Phase:** - The program iterates through the array to print each number and its difference from the average. This program provides a basic understanding of loops and arrays in Visual Basic, important for handling repetitive tasks and data storage.
### Programming Exercises

#### 1.
a. Design the logic for a program that allows a user to enter 20 numbers, then displays them in the reverse order of entry.

b. Modify the reverse-display program so that the user can enter any amount of numbers up to 20 until a sentinel value is entered.

#### 2.
a. Design the logic for a program that allows a user to enter 20 numbers, then displays each number and its difference from the numeric average of the numbers entered.

b. Modify the program in Exercise 2a so that the user can enter any amount of numbers up to 20 until a sentinel value is entered.

#### 3.
a. Design the logic for a program that allows a user to enter 20 numbers, then displays all of the numbers, the largest number, and the smallest.

b. Modify the program in Exercise 3a so that the user can enter any amount of numbers up to 20 until a sentinel value is entered.

#### 4.
Trainers at Tom’s Athletic Club are encouraged to enroll new members. Write an application that allows Tom to enter the names of each of his 25 trainers and the number of new members each trainer has enrolled this year. Output is the number of trainers who have enrolled 0 to 5 members, 6 to 12 members, 13 to 20 members, and more than 20 members.

#### 5.
a. The Downdog Yoga Studio offers five types of classes, as shown in Table 6-1. Design a program that accepts a number representing a class and then displays the name of the class.

b. Modify the Downdog Yoga Studio program so that numeric class requests can be entered continuously until a sentinel value is entered. Then display each class number, name, and a count of the number of requests for each class.

**Table 6-1: Downdog Yoga Studio classes**

| Class Number | Class Name       |
|--------------|------------------|
| 1            | Yoga 1           |
| 2            | Yoga 2           |
| 3            | Children's Yoga  |
| 4            | Prenatal Yoga    |
| 5            | Senior Yoga      |

#### 6.
Search the web to discover the 10 most common user-selected passwords, and enter them in an array. Design a program that prompts a user for a password, and continue to prompt the user until the user has
Transcribed Image Text:### Programming Exercises #### 1. a. Design the logic for a program that allows a user to enter 20 numbers, then displays them in the reverse order of entry. b. Modify the reverse-display program so that the user can enter any amount of numbers up to 20 until a sentinel value is entered. #### 2. a. Design the logic for a program that allows a user to enter 20 numbers, then displays each number and its difference from the numeric average of the numbers entered. b. Modify the program in Exercise 2a so that the user can enter any amount of numbers up to 20 until a sentinel value is entered. #### 3. a. Design the logic for a program that allows a user to enter 20 numbers, then displays all of the numbers, the largest number, and the smallest. b. Modify the program in Exercise 3a so that the user can enter any amount of numbers up to 20 until a sentinel value is entered. #### 4. Trainers at Tom’s Athletic Club are encouraged to enroll new members. Write an application that allows Tom to enter the names of each of his 25 trainers and the number of new members each trainer has enrolled this year. Output is the number of trainers who have enrolled 0 to 5 members, 6 to 12 members, 13 to 20 members, and more than 20 members. #### 5. a. The Downdog Yoga Studio offers five types of classes, as shown in Table 6-1. Design a program that accepts a number representing a class and then displays the name of the class. b. Modify the Downdog Yoga Studio program so that numeric class requests can be entered continuously until a sentinel value is entered. Then display each class number, name, and a count of the number of requests for each class. **Table 6-1: Downdog Yoga Studio classes** | Class Number | Class Name | |--------------|------------------| | 1 | Yoga 1 | | 2 | Yoga 2 | | 3 | Children's Yoga | | 4 | Prenatal Yoga | | 5 | Senior Yoga | #### 6. Search the web to discover the 10 most common user-selected passwords, and enter them in an array. Design a program that prompts a user for a password, and continue to prompt the user until the user has
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education