[try Beta version]
Not logged in

 
Vector program

Mar 17, 2016 at 12:17am
I need to write a program that reads 10 integers from the user and stores them in a vector, calculate the average of these 10 numbers and print the numbers in the vector that are less than or equal to the average. I am only looking for help with the first part, getting and storing the integers from the user. How do I ask for and store multiple variables in a vector?
Also, I am only allowed to use:

1
2
3
#include <iostream>
#include <vector>
using namespace std;
Last edited on Mar 17, 2016 at 1:00am
Mar 17, 2016 at 2:20am
1
2
3
vector<int> vec;
int num;
while(cin >> num) vec.push_back(num);

Use CTRL-Z to break out of the loop.
Last edited on Mar 17, 2016 at 2:21am
Topic archived. No new replies allowed.