1
I have the following verification code to know if a certain number belongs to a vector. I couldn’t think of a more precise way to get the program to say that the number DOES NOT belong to the vector, just that it belongs and its position within it. Can you help me get the "number is not part of the array" message displayed after the check? (in a more streamlined way)
Code:
#include <iostream>
using namespace std;
int main()
{
int vetor[5] = {10, 20, 30, 40, 50};
int N;
cout << "digite um numero: " << endl;
cin >> N;
for(int i = 0; i <=4; i++)
{
if(N == vetor[i])
cout << "O numero faz parte do vetor e está na " << i+1 << " posicao" << endl;
}
return 0;
}
I had thought about using another if, but I didn’t know how. It was too good this explanation, because I didn’t know how to use variables like Boolean. Thank you Victor Stafusa!
– Elder Son