Question

In: Computer Science

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, Y

userPattern:  R, R, G, B, B, R, Y, B, G, Y


image.png

Solutions

Expert Solution

Screenshot of the code:

Sample Output:

Code to copy:

//Include the header files.

#include

#include

//Define the main() function.

int main(void)

{

     //Declare and initialize the variables.

     char simonPattern[50] = "";

     char userPattern[50] = "";

     int userScore = 0;

     int i = 0;

     //Initialize the variable.

     userScore = 0;

//Copy the strings in the string variables.

     strcpy(simonPattern, "RRGBRYYBGY");

     strcpy(userPattern, "RRGBBRYBGY");

     //Begin the for loop.

     for(i=0; i < strlen(simonPattern); i++)

     {

          //Check the strings to be same.

          if(simonPattern[i] == userPattern[i])

         {

               //Increase the userScore by 1.

               userScore++;

         }//End of if condition.

          //Else part of if.

        else

        {

               //Break the program.

               break;

        }//End of else part.

     }//End of for loop.

     //Display the userScores.

     printf("userScore: %d\n", userScore);

     //Return the value for the main()

     //function.

     return 0;

}//End of the main() function.


Related Solutions

"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 (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...
(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
(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
For this question, a block is a sequence of 20 characters, where each character is one...
For this question, a block is a sequence of 20 characters, where each character is one of the 26 lowercase letters a-z. For example, these are blocks: iwpiybhunrplsovrowyt rpulxfsqrixjhrtjmcrr fxfpwdhwgxtdaqtmxmlf How many different blocks are there? A block is squarefree if no character appears two times consecutively. The first and third example above are squarefree, but the second example is not because of the two consecutive occurrences of r. How many squarefree blocks are there? A block is non-local if...
2. Non-Local Strings For this question, a block is a sequence of 20 characters, where each...
2. Non-Local Strings For this question, a block is a sequence of 20 characters, where each character is one of the 26 lowercase letters a-z. For example, these are blocks: iwpiybhunrplsovrowyt rpulxfsqrixjhrtjmcrr fxfpwdhwgxtdaqtmxmlf How many different blocks are there? A block is squarefree if no character appears two times consecutively. The first and third example above are squarefree, but the second example is not because of the two consecutive occurrences of r. How many squarefree blocks are there? A block...
I would like to create a Memory Game using JCreator. But am unsure where to start....
I would like to create a Memory Game using JCreator. But am unsure where to start. Please help. I would like to start with a basic code so I can add and change designs and colors ect... Any help would be greatly appreciated. I do want to use pics such as .jpg in my code.
Write a R-script to (and show the outputs of your code) (a) Create a sequence of...
Write a R-script to (and show the outputs of your code) (a) Create a sequence of numbers starting at 3.5 and ending at 10.7 with increments of 0.79. Find the variance and mean of those numbers. And finally sort the vector in a decreasing manner (b) Create a 3 different 3 by 3 matrices such that each of the numbers 1,2,...,9 appear exactly once (Sudoku style) in each of the matrices.
Python 3 A program will be written that outputs various geometric shapes, rendered in characters, line-by-line...
Python 3 A program will be written that outputs various geometric shapes, rendered in characters, line-by-line using nested loops. Here is what you need to know: 1- Copy this and don't change the inputs in the provided code: # Get the size and drawing character from the user size = input('Please enter the size: ') # Validate the input, exit if bad if size.isdigit(): size = int(size) else: print("Exiting, you didn't enter a number:", size) exit(1) # Input the drawing...
Simon Sinek says the idea that great leaders and organizations use is the golden circle consisting...
Simon Sinek says the idea that great leaders and organizations use is the golden circle consisting of what, how, and why. He explained these three components and how leaders use this. How you feel these should be executed in today's business world? I am looking for good, thought out answers with a lot of depth.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT