QAProgramming › Set hasDigit to true if the 3-character passCode contains a digit.
Q

Set hasDigit to true if the 3-character passCode contains a digit.

#include #include #include using namespace std; int main() { bool hasDigit; string passCode; hasDigit = false; passCode = "abc"; / Your solution goes here / if (hasDigit) { cout << "Has a digit." << endl; } else { cout << "Has no digit." << endl; } return 0; }
A

Here’s your solution, integrated into the code:

#include
#include
#include
using namespace std;

int main() {
bool hasDigit;
string passCode;
hasDigit = false;

passCode = “abc”;

/* Your solution goes here */
if (isdigit(passCode.at(0)) || isdigit(passCode.at(1)) || isdigit(passCode.at(2)))
{
hasDigit = true;
}

if (hasDigit) {
cout << “Has a digit.” << endl;
}
else {
cout << “Has no digit.” << endl;
}

return 0;
}

4 years ago
529 Views