Computers and Technology
02.08.2020 04:34
256
277
4
Solved by an expert

Write a program that reads an unspecified number of integers, determines how many

Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. Sample Run 1 Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is 3 The number of negatives is 1 The total is 5.0 The average is 1.25 Sample Run 2 Enter an integer, the input ends if it is 0: 0 No numbers are entered except 0 Sample Run 3 Enter an integer, the input ends if it is 0: 2 3 4 5 0 The number of positives is 4 The number of negatives is 0 The total is 14 The average is 3.5 Sample Run 4 Enter an integer, the input ends if it is 0: -4 3 2 -1 0 The number of positives is 2 The number of negatives is 2 The total is 0 The average is 0.0
Show Answers
bellapimienta8
bellapimienta8
5,0(86 marks)

C++

#include <iostream>

#include <vector>

using namespace std;

int main() {

  vector<int> v;

   int n = 1;

   while (n != 0) {

       cout<<"Enter an integer, the input ends if it is 0: ";

       cin>>n;

       v.push_back(n);

   }

   cout<<endl;

   

   int sum = 0;

   int num_positives = 0, num_negatives = 0;

   for (int i=0; i<v.size()-1; i++) {

       if (v[i] > 0)

           ++num_positives;

       else

           ++num_negatives;

           

       sum = sum + v[i];

   }

   

   cout<<"The number of positives is "<<num_positives<<endl;

   cout<<"The number of negatives is "<<num_negatives<<endl;

   cout<<"The total is "<<sum<<endl;

   cout<<"The average is "<<(float)sum/(v.size()-1);

   

   return 0;

}

yoboi33
yoboi33
4,4(45 marks)
The answer is D hope it helps pls mark brainlest

Popular Questions about the subject: Computers and Technology

Old-fashioned photographs from the nineteenth century are not quite...
Computers and Technology
21.03.2022 01:22
Write the css to configure a class that will produce a headline with...
Computers and Technology
16.11.2022 14:19
Write a for loop to print all NUM_VALS elements of vector hourlyTemp....
Computers and Technology
18.06.2021 13:44
Students(sid: integer, sname: string, major: string) Courses(cid: integer,...
Computers and Technology
10.02.2021 11:17
PLS help im in the middle of this test If someone enjoys the technical...
Computers and Technology
21.11.2022 07:04
What refers to the level at which a player is interacting with a story...
Computers and Technology
09.01.2023 15:40
Edhesive 8.3 lesson practice pls help...
Computers and Technology
04.11.2022 10:32
Computer-Assisted Instruction) The use of computers in education is...
Computers and Technology
23.10.2020 00:21
Edmund wants to create a website for his company. he has created all...
Computers and Technology
01.02.2021 03:17
Is the following relation well-founded? Justify your answer. The order...
Computers and Technology
02.05.2022 22:32

New questions by subject

What are essential amino acids?...
Health
20.10.2021 02:03
Which part of the hydrocarbon name tells you the amount of carbon in...
Chemistry
21.06.2023 19:39
Factor 8d^2 - 18 ? HELP PLEASE...
Mathematics
12.05.2020 16:30
Staudinger argues that openness to experience is highly correlated with...
Social Studies
17.02.2022 12:36
Describe in your own words three (3) examples of corruption during the...
History
01.02.2022 02:05
this graph shows the outside temperature (in degrees celsius) over the...
Mathematics
03.02.2020 07:38
The velocity of a 10.0 kg object that has 720 J of kinetic energy is...
Physics
08.02.2023 05:40
#
#
#
#
# #

We expand our knowledge with many expert answers