1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MArishka [77]
4 years ago
10

This program is to read in a list of integers until the value of -999 is input. Complete the program so that it prints out the n

umber of values read, the total of these values, and the average of these values. 1. Declare the proper variables for the number of values (count), total, and average 2. In the while loop, update your variables after reading a new value 3. Calculate the average 4. Display average, count, and total. The printf statements are already given in the base code.
The code I need to edit is below in C programming language.

#include

int main (int argc, char** argv)

{

int val;



/* prompt the user for input */

printf ("Enter in a list of numbers followed by the terminal value of -999\n");

/* loop until the user enters -999 */

scanf ("%d", &val);

while (val != -999)

{

scanf("%d", &val);

}

/* calculate the average of the values read in */




/* display the results */

/* use the following printf statements to display the results */

/* remove the comments */

//printf ("For the list of %d numbers with a total of %d\n", count, total);

//printf (" the average is: %15.5f\n", average);

return 0;

}
Computers and Technology
1 answer:
kvv77 [185]4 years ago
7 0

Answer:

#include <stdio.h>

int main()

{

   int val, total = 0, count = 0;

   float average = 0;

   printf ("Enter in a list of numbers followed by the terminal value of -999\n");

   scanf ("%d", &val);

   while (val != -999){

   

       if(val != -999){

           total += val;

           count++;

       }

       

       scanf("%d", &val);

   }

   

   average = (float)total / count;

   

   printf ("For the list of %d numbers with a total of %d\n", count, total);

   

   printf (" the average is: %15.5f\n", average);

   return 0;

}

Explanation:

Declare the total, count and average variables

In the while loop:

Add the entered number to the total and increment the count by 1 unless it is -999

Calculate average, divide total by count (Typecast the total as float to get decimal result)

You might be interested in
The five major functional areas consist of the Command Staff as a whole and the four sections in the General Staff: Operations,
inn [45]

The five major functional areas consist of the Command Staff as a whole and the four sections in the General Staff: Operations, Planning, Logistics, and Finance and Administration. Of these, the planning section consists of resource unit, situation unit, demobilization unit, and the documentation unit.

<u>Explanation:</u>

The Resource unit looks after the allocation, analysis, and organization of resources.

The situation unit collects information about The status of a particular incident that takes place in an organization.

The Demobilization unit is responsible for preparing a demobilization plan. It is responsible for the safety of persons and machines in case of any incident.

The Documentation unit looks after all the documents and prepares them on time.

8 0
3 years ago
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per ga
aliya0001 [1]

Answer:

public class TestAutomobiles {

   public static void main(String args[]) {

     Automobile obj = new Automobile(1, "Wolkswagen", "Golf", 2007, "GR1GR", 20, 120, "Grey");

  System.out.println("Initial Speed: " + obj.getSpeed());

  System.out.println("Current Speed with acceleration 100: " + obj.accelerate(100));

  System.out.println("Current Speed after using brake : " + obj.brake());

   }

}

class Automobile {

    private int idNumber, year, milesPerGallon, speed = 0;

    private String model, vinNumber, make, color;

   

    public void setIdNumber(int idNumber){

       if (idNumber >= 0 && idNumber <= 9999)

           this.idNumber = idNumber;

       else this.idNumber = 0;

    }

    public void setModel(String model){

        this.model = model;

    }

    public void setYear(int year){

       if (year >= 2000 && year <= 2017)

           this.idNumber = idNumber;

       else this.year = 0;

    }

    public void setVinNumber(String vinNumber){

        this.vinNumber = vinNumber;

    }

    public void setMilesPerGalon(int milesPerGallon){

       if (milesPerGallon >= 10 && year <= 60)

           this.milesPerGallon = milesPerGallon;

       else this.milesPerGallon = 0;

    }

    public void setSpeed(int speed){

        this.speed = speed;

    }

    public void setMake(String make){

        this.make = make;

    }

    public void setColor(String color){

        this.color = color;

    }

    public int getIdNumber(){return idNumber;}

    public String getModel(){return model;}

    public int getYear(){return year;}

    public String getVinNumber(){return vinNumber;}

    public int getMilesPerGallon(){return milesPerGallon;}

    public int getSpeed(){return speed;}

    public String getMake(){return make;}

    public String getColor(){return color;}

   

   public int accelerate() {

       setSpeed(speed + 5);

       return speed;

   }

   public int brake() {

       setSpeed(speed - 5);

       return speed;

   }

   public int accelerate(int s) {

       setSpeed(speed + s);

       return speed;

   }

   public int brake(int s) {

       setSpeed(speed - s);

       return speed;

   }

   

    public Automobile(int idNumber, String make, String model, int year, String vinNumber, int milesPerGallon, int speed, String color){

       setIdNumber(idNumber);

       setModel(model);

       setYear(year);

       setVinNumber(vinNumber);

       setMilesPerGalon(milesPerGallon);

       setSpeed(speed);

       setMake(make);

       setColor(color);

    }

}

Explanation:

Required <em>variables</em> are declared as private members.

Their <em>setters</em> and <em>getter</em> are created.

Two <em>accelearate</em> and two <em>break</em> methods are created.

One <em>constructor</em> taking all variables as parameter is created.

In the main, I tested a few functions to check if they work properly.

4 0
3 years ago
John is constructing a circuit. He wants a device which can store energy and can be used at any given time. Which device can he
zubka84 [21]

Answer:

capacitor

Explanation:

3 0
3 years ago
Read 2 more answers
What is the best list to use to speed up a research plan
iren2701 [21]

Answer:

Well here is what I got

Explanation:

1. Title

2. Abstract or summary

3. Background, context or rationale

4. Aims and objectives

5. Hypothesis

6. Literature review

7. Research design and methods

8. Ethical issues

9. Project timetable

10. Deliverables, outputs and outcomes

11. Risk assessment

12. Resources and costs

13. Project evaluation

14. References

15. Appendices

Hope I helped. Pls mark mine as brainliest

6 0
3 years ago
How can you avoid becoming a victim of identity theft?
Anna007 [38]
1. change your pw every month. 
2. dont give out your pw.


I hope this helps and have a wonderful day!!

<3
6 0
3 years ago
Read 2 more answers
Other questions:
  • PriQueue inherits from Queue. In the implementation of the getMax() method in the PriQueue class, we need to read and write the
    5·1 answer
  • For the question below, refer to the following recursive factorial method.
    8·1 answer
  • What binary number is the output of adding 1001011 and 100000?
    13·1 answer
  • Take the hypothetical situation that your business is considering a move to the cloud for core systems that contain confidential
    8·1 answer
  • Suppose we are working with an error-correcting code that will allow all single-bit errors to be corrected for memory words of l
    5·1 answer
  • Send me friend rq ;)
    14·2 answers
  • Ano ang<br> rotasyon ng daigdig​
    13·2 answers
  • Should people who download music and movies illegally be punished?
    12·1 answer
  • What does this icon mean? <br> Plz hurry it’s for a school quiz you will get a brainly
    10·1 answer
  • Mary uploaded some images on her website. She chose an image and downloaded it. She found that the image she saw on screen did n
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!