Need help writing this program!

Im a beginner to C++. Its my first year in college. Im completely stuck at this. Can anyone post a program of how it would look for this problem? Here is a picture of the problem. If you guys could use the numbers "2, 6, and 9" That would be great. Thanks in advance guys!

http://i.imgur.com/cewJm3z.jpg
closed account (zybCM4Gy)
Hm,

I dunno how far into the course you are but if I were you...

I would ask the user how many floating numbers they wish to enter.
Then using Dynamic Memory allocation create a memory space for an array of floating point numbers.

Then use a for loop to enter each number into the array until there are no numbers left.

Once you've stored that array, then you can create functions to the rest of the items.

*wondering whether it might be more useful to have a vector instead of array*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>


int main()
{
    std::cout << "How many values do you want to enter?" << std::endl;
    unsigned n;
    std::cin >> n;
    std::vector<float> values(n);
    std::cout << "Enter " << n << " values:" << std::endl;
    std::copy_n(std::istream_iterator<float>(std::cin), n, values.begin());
    std::cout << "Average of values is " <<
                ( std::accumulate(values.begin(), values.end(), 0.0) / n ) << std::endl;
    auto minmax = std::minmax_element(values.begin(), values.end());
    std::cout << "Minimum is " << *minmax.first  << std::endl;
    std::cout << "Maximum is " << *minmax.second << std::endl;
    std::cout << "Range is "   << *minmax.second - *minmax. first;
}

http://ideone.com/ue5O6c
Topic archived. No new replies allowed.