Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

Hello all. First time working with vectors in C++, and I'm having a bit of an issue. My goal is to have a vector of 70 random integers ranging from 30 to 50, print out each integer, and find the average value of all 50 numbers. This is what I have thus far.

OpenStudy (anonymous):

#include <iostream> #include <vector> #include <ctime> #include <cstdlib> using namespace std; int main() { vector <int> temp; int randNum; srand(time(NULL)); int sum; for(int i = 0; i < 70; i++) { randNum = rand() % 50 + 1; temp.push_back(randNum); } for (int i = 0; i <= 70; i++) { sum += temp[i]; } float average = sum / 70; cout << "The average is " << average; return 0; }

OpenStudy (rsmith6559):

So far, so good. You may want to add and endl to your cout.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!