Question

In: Computer Science

(C++) "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

Simon Says is a memory game where Simon outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the seq

(C++) "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. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4: 

simonPattern: RRGBRYYBGY 

userPattern: RRGBBRYBGY


Solutions

Expert Solution

Output

//This code assumes simon to be a computer and thus generates a random text for simon
#include
#include
#include
#include
using namespace std;
int main()
{
//this is done so that we get new output every time the program is executed
srand(time(0));
char arr[4]={'R','G','B','Y'};
string simon="",user;
int score=0;
//Assigning string to simon
for(int i=0;i<10;++i)
{
simon+=arr[rand()%4];
}
cout<<"simonPattern: "< cout<<"userPattern: ";
cin>>user;
//Checking simon pattern with user pattern
for(int i=0;i<10;++i)
{
if(simon[i]==user[i])
score++;
//The loop breaks if the character isnt same
else
break;
}
//The program outputs the score at the end
cout<<"userScore: "< return 0;
}


Related Solutions

"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.
For 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. Ex: The following patterns yield a userScore of 4: simonPattern: R, R, G, B, R, Y, Y, B, G, Yimport java.util.Scanner;public class SimonSays...
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G,...
"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. Assume simonPattern and userPattern are always the same length. Ex: The following patterns yield a userScore of 4: simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY #include <stdio.h>...
"Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G,...
"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. Ex: The following patterns yield a userScore of 4: simonPattern: RRGBRYYBGY userPattern: RRGBBRYBGY
Simon Says' is a memory game where 'Simon' outputs a sequence of 10 characters
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. Ex: The following patterns yield a userScore of 4:simonPattern: R, R, G, B, R, Y, Y, B, G, YuserPattern:  R, R, G, B, B,...
Given Y=120, TR=10, C=70, T=40, G=45. Total S (saving) = ____. Select one: A. 3 B....
Given Y=120, TR=10, C=70, T=40, G=45. Total S (saving) = ____. Select one: A. 3 B. 5 C. 7 D. 9 E. 11
Design a combinational circuit with four inputs (A, B, C and D) and four outputs (W, X, Y and Z). When the binary input is less than 10 the binary output is two greater than the input. When the binary input is equal or greater than 10 the binary output
Design a combinational circuit with four inputs (A, B, C and D) and four outputs (W, X, Y and Z). When the binary input is less than ten the binary output is two greater than the input. When the binary input is equal or greater than ten the binary output is three less than the input.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT