# Thread: Short and simple question on C/C++.

1. ## Short and simple question on C/C++.

Hello, I've got a simple question:

I need something to happen, only if, within a vector, there is enough vector positions equal to a value/s.

For instance, I have vector[10]

while(4 out of 10 positions in the vector, no matter which = 1)
{something something}

Thanks for any help.

2. 1st: What?

3. 1st: Was I not clear enough?
2nd: I will ignore this part. To start trouble, I'm not the one.

It's simple, let's say:
vector[1] = 3, vector[2]= 5, vector[3] = 3, vector[4] = 9, vector[5] = 4

I need that, if 2 out of the 5 vector positions have value=3, then something(printf, scanf, w/e) would happen... If it isn't clear enough I'm sorry but I can't find any other way to explain it!!

1st: Was I not clear enough?
No, you weren't. In fact I think you probably deserve an award for the most poorly posed question of all time.

2nd: I will ignore this part. To start trouble, I'm not the one.

It's simple, let's say:
vector[1] = 3, vector[2]= 5, vector[3] = 3, vector[4] = 9, vector[5] = 4

I need that, if 2 out of the 5 vector positions have value=3, then something(printf, scanf, w/e) would happen... If it isn't clear enough I'm sorry but I can't find any other way to explain it!!
As previously stated. We don't just hand out code. The whole point of this forum is to learn, which means that if you want our help you have to post an initial attempt and we will help you from there.

5. Originally Posted by Swarvy
No, you weren't. In fact I think you probably deserve an award for the most poorly posed question of all time.
You deserve an award for the most sympathetic and charming person then. And I am being ironic.

Code:
`As previously stated. We don't just hand out code. The whole point of this forum is to learn, which means that if you want our help you have to post an initial attempt and we will help you from there.`

I've seen many many code handouts, and I've been around for a couple of days only.

But I get your point, and I'm not expecting you to code a whole program for me, nor did I ever intend you to. I never said "code this", did I?

Anyways, here goes what I'm trying to do, in a "neanderthal" way:
Code:
```if(vector[1]==2 && vector[2]==1 && vector[3]==1 && vector[4]==1)
{printf("There are at least 3 vector positions with the value 1");}

if(vector[1]==1 && vector[2]==2 && vector[3]==1 && vector[4]==1)
{printf("There are at least 3 vector positions with the value 1");}

if(vector[1]==1 && vector[2]==1 && vector[3]==2 && vector[4]==1)
{printf("There are at least 3 vector positions with the value 1");}

if(vector[1]==1 && vector[2]==1 && vector[3]==1 && vector[4]==2)
{printf("There are at least 3 vector positions with the value 1");}```
Now, imagine the above, with a 40 positions vector in which I need, say 15 positions to be = 1. I'd be years to do so. So my questions is, if any of you happen to know a simpler way to do this. Thanks.

6. You need loop.
Pseudo code:
Code:
```count = 0;
while( v in vector) {
if( v == a) count++;
}
printf("There are at least %d vector(s) with the value %d\n",count,a);```

7. Originally Posted by Bayint Naung
You need loop.
Pseudo code:
Code:
```count = 0;
while( v in vector) {
if( v == a) count++;
}
printf("There are at least %d vector(s) with the value %d\n",count,a);```
Couldn't figure out the "v in vector", but you gave me an idea to solve the problem. Thanks.