Write a sentinel-controlled while loop that accumulates a set of integer test scores input by the user until negative 99 is entered.

Answers

Answer 1

Answer:

Here is the sentinel-controlled while loop:

#include <iostream> //to use input output functions

using namespace std; // to identify objects like cin cout

int main(){ // start of main() function body

int test_score; // declare an integer variable for test scores

//prompts user to enter test scores and type-99 to stop entering scores

cout << "Enter the test scores (enter -99 to stop): ";

cin >> test_score; // reads test scores from user

while (test_score != -99){ // while loop keeps executing until user enters -99

cin >> test_score; } } // keeps taking and reading test scores from user

Explanation:

while loop in the above chunk of code keeps taking input scores from user until -99 is entered. Sentinel-controlled loops keep repeating until a sentinel value is entered. This sentinel value indicates the end of the data entry such as here the sentinel value is -99 which stops the while loop from iterating and taking the test score input from user.

The complete question is that the code should then report how many scores were  entered and the average of these scores. Do not count the end sentinel -99 as a score.

So the program that takes input scores and computes the number of scores entered and average of these scores is given below.

#include <iostream>  // to use input output functions

using namespace std;  // to identify objects like cin cout

int main(){  //start of main function body

double sum = 0.0;  // declares sum variable to hold the sum of test scores

int test_score,count =0;  

/* declares test_scores variable to hold the test scores entered by user and count variable to count how many test scores input by user */

cout << "Enter the test scores (or -99 to stop: ";

//prompts user to enter test scores and type-99 to stop entering scores

cin >> test_score;  // reads test scores from user

while (test_score != -99){  // while loop keeps executing until user enters -99

count++;  /* increments count variable each time a test cores is input by user to count the number of times user entered test scores */

sum = sum + test_score;  // adds the test scores

cin >> test_score;}  // reads test scores from user

if (count == 0)  // if user enters no test score displays the following message

cout << "No score entered by the user" << endl;

else  //if user enters test scores

//displays the numbers of times test scores are entered by user

cout<<"The number of test scores entered: "<<count;

/* displays average of test scores by dividing the sum of input test scores with the total number of input test scores */

cout << "\n The average of " << count << " test scores: " <<sum / count << endl;}

The program along with its output is attached.

Write A Sentinel-controlled While Loop That Accumulates A Set Of Integer Test Scores Input By The User

Related Questions

4. Discuss the advantages and disadvantages of using the same system call interface for both files and devices. Why do you think operating system designers would use the same interface for both

Answers

Answer:

According to the principles of design, Repetition refers to the recurrence of elements of the design

One of the advantages of this is that it affords uniformity. Another is that it keeps the user of such a system familiar or with the interface of the operating system.

One major drawback of this principle especially as used in the question is that it creates a familiar route for hackers.

Another drawback is that creates what is called "repetition blindness". This normally occurs with perceptual identification tasks.

The  phenomenon may be  due to a failure in sensory analysis to process the same shape, figures or objects.

Cheers!

Other Questions
Which answers are equivalent to the fraction below? Check all that apply12/16A.1/2 B.6/8 C2/3 D.2/6 E.3/4 F.6/4 What is radioactive dating?A. A method of determining the age of a fosall based on the amountof certain isotopes that remain in a fossil or rockB. A method of determining the age of a fossil that estimates the ageof the organism at its deathC. A method of determining the age of a fossil based on acomparison to the age of other similar fossilD. A method of determining the age of a fossil that estimates howclosely related various fossilized organisms were Which event resulted directly from the growth of railroads in the 19th century?A. More women participated in the workforce.B. Banking practices became fairer to farmers.C. Standardized time zones were created.D. Child labor practices were improved. Use the graph to complete the given statements. Enter the letters A, B, C, or D in the boxes.The function with the lowest output values as x approaches infinity is _. The function with the greatest output values as x approaches infinity is _. Gwendolyn shot a coin with a sling shot up into the air from the top of a building. The graph below represents the height of the coin afterx seconds. HELP ASAP Linear Relations Question The accompanying graph shows the amount ofwater left in Rover's water dish over a period oftime.Amount of Water in Rover's Water Dish500400300Amount of Water (mL)2001000 15 30 45 60 75 90 105Time (seconds)How long did Rover wait from the end of his firstdrink to the start of his second drink of water?A10 secB. 30 secC. 60 secD. 75 sec Which of the following functions is graphed below? Jason has bought a new pool and has already measured some of the sides. Using the figure below and your knowledge of quadrilaterals, solve for x and y. Determine the [OH] concentration in a 0.344 M Ca(OH) solution. Individuals who have chronic bronchitis most often have:________. A. a productive cough. B. normal lung sounds. C. a barrel chest. D. substantial weight loss. find the value of x if (1.1)^x=100 . A box contains four red, three yellow, and seven green balls. Three balls are randomly selected from the box without replacement. (a) What is the probability that all three balls are the same colo Two different families pay for entry into a water park. Family 1 has 2 adults and 3 children and costs a total of 20 to enter the park.Family 2 has 1 adult and 4 children and costs a total of 15 to enter the park. Work out the cost of the adult ticket, and the child ticket. Toby cuts a pizza into 6 equal slices. He eats half a slice. What fraction of the pizza has he eaten? Which statements are true regarding the diagram? Check all that apply.The side opposite the 60 angle has a length of The side opposite the 60 angle has a length of .sin(60) = sin(60) = The other acute angle of the triangle is 30. What is the one single most important reason that human impact on the planet has been so great? Can someone help me with this question please. Which scenario describes allopatric speciation?A) A population of squirrels is separated by the Grand Canyon. The twosubpopulations evolve into two distinct species.B) A tetraploid plant species evolves from a diploid ancestor. Both the tetraploidand diploid species are found in the same habitat.C) One population breeds in the fall; another population breeds in the spring.D) A male horse and a female donkey mate, producing a sterile hinny. WhywereRepublican Roman sculpturesSOextremely realistic?