24/09/2016
It may be often that we face bugs in our codes. As some of them may be debugged by writing few extra lines of codes, some surprisingly involve removing them. Some may cause our code not to run in the first place, while others can crush it in the runtime. And some may do neither and just give us results we do not expect as in the case of a code put below. ;)
The following code is written by a junior C++ programmer. He, as an IT expert in a bank he works in, wanted to make a system to impress his boss and get himself a raise. One part of his system, shown here, simply lets a user to enter their ID and checks whether their data exists or doesn’t. He tried entering 2 IDs one that exists and another that does not. (Namely 44058 and 22022).
At this point he is confident that this section of his system is bug free and fully functional, as the two IDs returned values expected. Unfortunately, he must have missed something that, while he was showing his system to his B0$$, he noticed a bug. What an awkward moment that nobody wants to be in!
entered 12506, that should have returned a positive value.
See what you can do to help him out. ;)
using namespace std;
int userID, database [] = {15203, 12506, 99025, 44058};
bool doesCustomerDataExist(int input);
int main()
{
cout > userID;
if(doesCustomerDataExist(userID)) cout