PLEASE ANSWER IN C++ NOT JAVA \"Simon Says\" is a memory game where \"Simon\" ou
ID: 3804620 • Letter: P
Question
PLEASE ANSWER IN C++ NOT JAVA
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequence. Create a for loop that compares the two strings starting from index 0. For each match, add one point to userScore. Upon a mismatch, exit the loop using a break statement.
PLEASE ANSWER IN C++ NOT JAVA
Ex: The following patterns yield a userScore of 4: ALSO NEED SO IT CAN DO OTHER userScore of 9:
4
Testing: RRRRRRRRRR/RRRRRRRRRY
9
4
Tests aborted.
Your value:4
Explanation / Answer
code:
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
cout<<"enter simon string";
string str1;
cin>>str1;
cout<<"enter user string";
string str2;
cin>>str2;
int i=0;
int userscore =0;
while(i<str1.size() && str1[i]==str2[i])
{
userscore++;
i++;
}
cout<<"userscore is :"<<userscore;
return 0;
}
sample output:
mitali@Infoweave:~/Desktop/chegg$ ./a.out
enter simon stringRGB
enter user stringRGR
userscore is :2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.