Question
Task 3: Write a program to calculate simple statistics Enter n points, calculate their sum and average, find the smallest value, largest value, and the
Task 3: Write a program to calculate simple statistics Enter n points, calculate their sum and average, find the smallest value, largest value, and the range of the data points. Create a new project named "Lab5-3." Create your program piece by piece, adding just one step at a time, building the program without errors, and then testing to determine that you have the correct results before proceeding to add the next part. When testing your program below, use the following inputs: Use 4 as the number of data points. Use the following data values: 12.5, 17, 3.2, 6 Step 1: Add declarations for number and sum as double variables, and count and limit as int variables. Assign 0.0 to sum and assign 0 to count. Add a prompt to request the number of data points to enter. Use scanf() to read this value into the variable limit. Print the variable read back to the output using this format "Entering %d data points." Build and test. Step 2: Add a while loop, which will loop while count is less than limit. Add one to count at the beginning of the while loop body. Output a prompt using the format "Enter data point %d: " using the count variable. Build and test. Step 3: After the prompt in the loop (added in step 2), use scanf() to input the data point into the variable number. Add number to sum, so that sum contains a total of all numbers entered so far. Output the sum after the end of the loop. (Include descriptive text in the output of the sum.) Build and test. (The program should display 38.7 as the sum.) Step 4: Add another double variable named average. After the end of the loop, calculate the average as the sum divided by the count. Output the average, along with descriptive text. Build and test. (The program should display 9.675 as the average, using the test data above.) Step 5: Add three more double variables: smallest, largest, and range. Inside the loop body, at the end of the loop, add an if-else statement. If the count is 1, assign number to smallest, and also assign number to largest. Else, if the count is not 1, add a nested if statement. If number is less than smallest, assign number to smallest. Also, if number is greater than largest, assign number to largest. After the end of the loop, add code to output the smallest and largest numbers, along with descriptive text. Build and test. (The smallest number is 3.2, and the largest number is 17.) Step 6: After the end of the loop, calculate the range as the largest minus the smallest. Add a statement to output the range, along with descriptive text. Build and test. (The range should display as 13.8.) Double-check that your program has the proper header comments with your name and other class information. Copy your working while-loop program and include it in the deliverables to submit to the instructor for grading. Step 7: Convert the while loop in your program to the for loop. Build and test that your program still works. Double-check that your program uses the correct indentation, that it has the proper header comments, and that you have used proper line spacing to separate different functions in the program. Include a few explanatory comments in the program. Build and test.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started