Welcome to Westonci.ca, where finding answers to your questions is made simple by our community of experts. Get immediate and reliable solutions to your questions from a knowledgeable community of professionals on our platform. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.
Sagot :
Answer:
In C++:
#include <iostream>
using namespace std;
int main(){
int userScore = 0;
string simonPattern, userPattern;
cout<<"Simon Pattern: "; cin>>simonPattern;
cout<<"User Pattern: "; cin>>userPattern;
for (int i =0; i < simonPattern.length();i++){
if(simonPattern[i]== userPattern[i]){
userScore++; }
else{ break; }
}
cout<<"Your value: "<<userScore;
return 0;
}
Explanation:
This initializes user score to 0
int userScore = 0;
This declares simonPattern and userPattern as string
string simonPattern, userPattern;
This gets input for simonPattern
cout<<"Simon Pattern: "; cin>>simonPattern;
This gets input for userPattern
cout<<"User Pattern: "; cin>>userPattern;
This iterates through each string
for (int i =0; i < simonPattern.length();i++){
This checks for matching characters
if(simonPattern[i]== userPattern[i]){
userScore++; }
This breaks the loop, if the characters mismatch
else{ break; }
}
This prints the number of consecutive matches
cout<<"Your value: "<<userScore;
Thanks for using our service. We're always here to provide accurate and up-to-date answers to all your queries. We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Get the answers you need at Westonci.ca. Stay informed by returning for our latest expert advice.