Answer:
#include <iostream> // includes input output functions
#include <string>
// used for string functions
using namespace std; // identifies objects like cout , cin
int main() { // body of the main function
int index; // index position of the elements
simonPattern = "RRGBRYYBGY"; //stores simon pattern
userPattern = "RRGBBRYBGY"; //stores user pattern
int userScore = 0; // used to store the user score
// loop compares characters of user and simon patterns
for ( index = 0; userPattern[index] == simonPattern[index]; ++index) {
userScore = userScore +1; // adds to the user score
if (userPattern[index] != simonPattern[index]){
//if user and simon pattern do not match
break; } } // breaks the loop
cout << "userScore is " << userScore; // prints the user score
Explanation:
The program compares the user pattern to simon pattern character by character and keeps adding one to the user score if the characters of both simon and user patterns match. The loop breaks if the character of user pattern does not match with that of simon matter. At the end the calculated user score is displayed in the output.