c++ - How does one pull a specific number from an array of randomly generated numbers using an if...else statement? -
bool statsarray::isnumberfound(int somenumber) { if (data[size] == somenumber) { cout << "congrats, have perfect score!" << endl; } else { cout << "sorry, not have perfect score." << endl; } return 0; }
not sure if i'm on right track, pull score of 100
using:
examdata.isnumberfound(100);
from array of randomly generated numbers.
what reasons using if-else statement here? iterate on elements using for-loop instead.
for(int = 0; < numofelements; i++) { if(data[i] == somenumber) { cout << "congrats, perfect score!" << endl; return true; } } // nothing matched.. cout << "sorry, not have perfect score." << endl; return false;