Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ Program: Compute an average of integer values Ask the user to enter a number of values to average in the range from

Write a C++ Program: Compute an average of integer values Ask the user to enter a number of values to average in the range from 2 to 10. Use a loop to make sure the entered number is within the range. Output an error message any time an invalid number is entered.

Once a valid number of values is entered ask the user to input each value. Enumerate the values being asked for (see the output example). Your goal is to calculate their average and output it to the console. Your program should have the following:

You should have 4 comment lines at the top: description of the program, author, section, and date.

Create your variables, use the appropriate type, name them appropriately (camelback notation), and remember to not leave them uninitialized.

You should define at least 3 named constants (or more if you wish but this is not a requirement). Identify the best candidates.

Ask the user to enter a number of values and read it from the console. If an invalid number is entered output an error message and ask to enter a number again.

Once you get a valid number of values ask for each value individually. Enumerate each value you are asking for.

Calculate the average and output it to the console. Your result should have three digits after the decimal point. Your output should look similar to the following: First run Enter a number of values from 2 to 10: 1 Invalid input! Enter a number of values from 2 to 10: 11 Invalid input! Enter a number of values from 2 to 10: 6 Enter value 1: 5 Enter value 2: 8 Enter value 3: 45 Enter value 4: 11

Enter value 5: 6 Enter value 6: 1 The average is 12.667 Second run Enter a number of values from 2 to 10: 4 Enter value 1: 41 Enter value 2: 55 Enter value 3: 12 Enter value 4: 9 The average is 29.250

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

11.5 Develop a central idea for a speech.

Answered: 1 week ago