You did not initialise amount, presumably to 0.
Printable View
You did not initialise amount, presumably to 0.
You never initialized the variable amount.
Domething like this would do the trick
KurtCode:int amount = 0; //The amount the number was found
Thanks everyone! It's working correctly.. =)Code:How many numbers do you wish to input?: 9
Number? 12
Number? 23
Number? 45
Number? 4332432141
Number? 34
Number? 23
Number? 12
Number? 9
Number? 2332432145254325325
What number do you wish to search for?: 23
The number 23 appeared 2 times.
That's good :)
Now, as hk_mp5kpdw hinted, you can actually use a function, count(), from <algorithm>, and thus replace:
with:Code:for (counterfind = 0; counterfind < length; ++counterfind)
{
if(list[counterfind] == number)
{
++amount;
}
}
std::cout << "The number " << number << " appeared " << amount << " times. \n";
Code:std::cout << "The number " << number << " appeared "
<< std::count(list, list + length, number)
<< " times. \n";
>> Now, as hk_mp5kpdw hinted, you can actually use a function, count(), from <algorithm>
Of course, that's good knowledge to remember along with vector for after you submit your assignment, since it is unlikely that such code would be appropriate to use there.