Answer:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string simonPattern = "RRGBRYYBGY";
string userPattern = "RRGBBRYBGY";
int score = 0;
for (int i = 0; i < simonPattern.length(); i++) {
if (userPattern[i] == simonPattern[i])
score++;
else
break;
}
cout << "Score is " << score << endl;
return 0;
}
Explanation:
Initialize the simonPattern, userPattern and score
Create a for loop that checks the each chracter in simonPattern with userPattern. If a character matches, increase the score by 1. Otherwise, stop the loop.
When the loop is done print the score
The code above will print 4 because the first four characters matches in the strings