Question

In: Other

"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>
#include <string.h>

int main(void) {
char simonPattern[50];
char userPattern[50];
int userScore;
int i;

userScore = 0;
strcpy(simonPattern, "RRGBRYYBGY");
strcpy(userPattern, "RRGBBRYBGY");

/* Your solution goes here */

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

return 0;
}

Solutions

Expert Solution

#include
#include

int main(void) {

char simonPattern[50];
char userPattern[50];
int userScore;
int i;

userScore = 0;
strcpy(simonPattern, "RRGBRYYBGY");
strcpy(userPattern, "RRGBBRYBGY");

/* Your solution goes here */

      for (i = 0; i < 10; i++) {
          if (simonPattern[i] == userPattern[i]) {
              userScore = userScore + 1;
          } 
          else
              break;
      }

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

return 0;

}


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. 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,...
"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
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.
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.
Consider a gambling game where a player pays $10 to play with a 40% chance of...
Consider a gambling game where a player pays $10 to play with a 40% chance of winning $20, 40% chance of winning $1, and a 20% chance of winning $0. (a) If the player’s utility function is U(M) = M, what is the expected utility from playing the game? How does it compare to the player’s utility of not playing the game, i.e. having $10 for sure? Is the player risk-neutral, risk-loving, or risk-averse, and does the player play? (b)...
Consider a game where each of 10 people randomly drop a dollar bill with their name...
Consider a game where each of 10 people randomly drop a dollar bill with their name on it into a bag and then take turns picking a dollar each from the bag. a) What is the probability that at least one person picks a bill with his name on it? b) Given that the first person to pick a bill with his name on it wins all the money, what are the chances of winning if you draw first? What...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT