QAProgramming › Write an expression to detect that the first character of userInput matches firstLetter.
Q

Write an expression to detect that the first character of userInput matches firstLetter.

Write an expression to detect that the first character of userInput matches firstLetter. #include #include using namespace std; int main() { string userInput; char firstLetter; getline(cin, userInput); cin >> firstLetter; if (/* Your solution goes here */) { cout << "Found match: " << firstLetter << endl; } else { cout << "No match: " << firstLetter << endl; } return 0; }
A

Hi! That’s simple – just insert this string:

if (userInput.at(0) == firstLetter) {

4 years ago
391 Views