Write a program that prompts the user to enter five test scores and then prints the average test score. Indicate the average test score by printing it to the terminal using the following format: Your average test score is: X

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
100%

C++

Write a program that prompts the user to enter five test scores and then prints the average test score. Indicate the average test score by printing it to the terminal using the following format:

Your average test score is: X

(Assume that the test scores are decimal numbers.)

!!! 3/
注
</>
Instructions
Write a program that prompts the user
to enter five test scores and then prints
the average test score. Indicate the
average test score by printing it to the
terminal using the following format:
Your average test score is: X
(Assume that the test scores are
decimal numbers.)
Grading
14
15
16
17
10 11 12 13
18
19
20
21
8
9
Nos p
2
4
5 int
6 {
7
3 us:
do
do
CO
ci
COU
cir
cou
cin
cout
cinx
cout
cin>
avg=
cout<
Transcribed Image Text:!!! 3/ 注 </> Instructions Write a program that prompts the user to enter five test scores and then prints the average test score. Indicate the average test score by printing it to the terminal using the following format: Your average test score is: X (Assume that the test scores are decimal numbers.) Grading 14 15 16 17 10 11 12 13 18 19 20 21 8 9 Nos p 2 4 5 int 6 { 7 3 us: do do CO ci COU cir cou cin cout cinx cout cin> avg= cout<
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Didn't necessarily come out correct when i ran it

### C++ Programming Code Overview

This image displays a screenshot of a C++ program alongside compilation errors found in the terminal.

#### Source Code (main.cpp)

```cpp
#include <iostream>

using namespace std;

int main()
{
    float sum=0; // Initialize the decimal sum to 0
    float number; // Declare number variable
    float average; // Declare the average variable

    cout<<"Enter five test scores:"; // Asking user to input five test scores

    for(int i=0; i<5; ++i) // Iterate loop 5 times
        cin>>number; // Input a number
        sum+=number; // Getting sum of all numbers

    average=sum/5; // Calculating the average of 5
    cout<<"Your average test score is: " << average; // Print the average of 5 numbers
}
```

#### Compilation Errors and Warnings

1. **Error: `sum` was not declared in this scope**  
   - The terminal shows an error indicating that `sum` was not declared in the scope where it was used. This is a confusion as `sum` is declared at the beginning of `main()`.
   
2. **Warning: Unused variable `i_0`**  
   - A warning indicates an unused variable `i_0`, which is misleading as it might be mistaken for a typo. The actual loop syntax `for(int i=0; i<5; ++i)` should be correct.

3. **Error in directory**  
   - The message `bash: ./a.out: No such file or directory` suggests that an executable file is expected but not found. This might be due to compilation errors preventing the creation of an executable.

### Explanation and Solutions

- **Loop and Syntax Correction**:  
  Ensure that the loop is properly formatted with opening and closing braces `{}` around the loop body to include both `cin>>number;` and `sum+=number;`.

- **Compiling and Running the Program**:  
  Fix the errors and ensure successful compilation with a command like `g++ main.cpp -o main`. After compilation, run the program using `./main`.

This explanation provides insights into common syntax errors and issues faced during compilation, helpful for beginners learning C++.
Transcribed Image Text:### C++ Programming Code Overview This image displays a screenshot of a C++ program alongside compilation errors found in the terminal. #### Source Code (main.cpp) ```cpp #include <iostream> using namespace std; int main() { float sum=0; // Initialize the decimal sum to 0 float number; // Declare number variable float average; // Declare the average variable cout<<"Enter five test scores:"; // Asking user to input five test scores for(int i=0; i<5; ++i) // Iterate loop 5 times cin>>number; // Input a number sum+=number; // Getting sum of all numbers average=sum/5; // Calculating the average of 5 cout<<"Your average test score is: " << average; // Print the average of 5 numbers } ``` #### Compilation Errors and Warnings 1. **Error: `sum` was not declared in this scope** - The terminal shows an error indicating that `sum` was not declared in the scope where it was used. This is a confusion as `sum` is declared at the beginning of `main()`. 2. **Warning: Unused variable `i_0`** - A warning indicates an unused variable `i_0`, which is misleading as it might be mistaken for a typo. The actual loop syntax `for(int i=0; i<5; ++i)` should be correct. 3. **Error in directory** - The message `bash: ./a.out: No such file or directory` suggests that an executable file is expected but not found. This might be due to compilation errors preventing the creation of an executable. ### Explanation and Solutions - **Loop and Syntax Correction**: Ensure that the loop is properly formatted with opening and closing braces `{}` around the loop body to include both `cin>>number;` and `sum+=number;`. - **Compiling and Running the Program**: Fix the errors and ensure successful compilation with a command like `g++ main.cpp -o main`. After compilation, run the program using `./main`. This explanation provides insights into common syntax errors and issues faced during compilation, helpful for beginners learning C++.
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Constants and Variables
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.
Similar questions
  • SEE MORE QUESTIONS
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