Help with problem

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <vector>


using namespace std;

int main()
{
	vector<int> nums;


	const int MAX = 10;
	int integers;

	for (int i = 0; i < 10; i++)

	{
		cout << "Enter 10 integers :" << endl;
		cin >> integers;
	}

	system("pause");
	return 0;
}
Last edited on
uhm. Why is your vector of strings if you want to input integers?

https://www.youtube.com/results?search_query=vectors+c%2B%2B

https://www.google.se/#q=vectors+c%2B%2B

Whichever you prefer.
Why do you have to make sure to use vectors?

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
        for(loop 10 times)
        {
                //enter values to vector
        }
 
        for(loop 10 times)
        {
                if(vector@elementNr > 10)
                {
                        cout<<valueOfElementNr<<endl;
                }
        }
}



Aint gonna do it for you but something like this i guess would work.
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
Use a condition then? For any element greater than 10, print it out.

Aceix.
I have to use vectors
Hello again. Since it seems you have been trying i made a code for you to watch and learn. This should work just fine

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <vector>
 
using namespace 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
Last edited on
Topic archived. No new replies allowed.