Using C Write a program that reads numbers from the input st

Using C++:

Write a program that reads numbers from the input stream until a zero is encountered. Display the average (rounded down to an integer), the maximum number and the

minimum number. Assume that numbers entered will be between 1 and 1000. For example:

Another example:

** Do not user DO loop, break or exit

Solution

Answer

#include <iostream>

#include <vector>

#include <algorithm>

int main(void)

{ std::vector<int> input;

int x, cnt = 0;

for(;;) {

std::cout << \"Enter a number: \";

std::cin >> x;

if (x == 0) break;

input.push_back(x);}

auto min_max =

std::minmax_element(input.begin(),input.end());

if (not input.empty())

std::cout << \"Average: \" <<

int(std::accumulate(input.begin(),input.end(), 0) /

input.size() ) << \"\ \"

<< \"Max: \" << *(min_max.second) << \"\ \";

<< \"Min: \" << *(min_max.first) << \"\ \";

else std::cout << \"No data, so no answers\ \"; }

Using C++: Write a program that reads numbers from the input stream until a zero is encountered. Display the average (rounded down to an integer), the maximum n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site