Hi I'm actually a working on a Networking degree but one of my electives is a C++ class. I have a problem I need to make sure I use vectors not static Arrays. I need to inter 10 integers and the output needs to be the number of integers that are greater than 10. Array must be filled before you do the calculation. I'm really struggling and don't have much yet. If anyone could help me solve this I'd really appreciate it.
1. Enter 10 values to your vector, random or not doesnt matter i guess.
2. Check the the first element, is it >10? Then go to the next element, is it >10?
3. Make a new array /vector for the values >10 or just output them right away.
I've figured out how to enter the integers but it doesn't look pretty. I need to get this in by tomorrow. I just need help getting it to output numbers greater that 10
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <vector>
usingnamespace std;
int main()
{
vector <int> myVector; // creating vector with int obv
srand (time(NULL));
for(int i=0; i<10; i++)
{
myVector.push_back(rand() %100); // assign a random number to the vector
// change %100 to % 20+1 if u want numbers 1-20
}
for(int i=0;i<10;i++)
{
if(myVector.at(i)>10) // check if the vector element at spot (i) is bigger than 10
cout<<myVector.at(i)<<endl;
}
return 0;
}
If you dont want random numbers let the user type 10 ints manually instead