Question #99430

Write an expression to detect that the first character of userInput matches firstLetter.
#include <iostream>
#include <string>
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;
}

Expert's answer

firstLetter == userInput[0]


LATEST TUTORIALS
APPROVED BY CLIENTS