1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vekshin1
3 years ago
12

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 se

quence. 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:
Ex: The following patterns yield a userScore of 9:
simonPattern: RRGBRYYBGY
userPattern: RRGBBRYBGY
Result: Can't get test 2 to occur when userScore is 9
Testing: RRGBRYYBGY/RRGBBRYBGY
Your value: 4
Testing: RRRRRRRRRR/RRRRRRRRRY
Expected value: 9
Your value: 4
Tests aborted.
Computers and Technology
1 answer:
Pepsi [2]3 years ago
6 0

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;

You might be interested in
Which line in the following program contains the header for the showDub function? 1 #include 2 using namespace std; 3 4 void sho
Flura [38]

Answer:

The answer to this question is "15 line".

Explanation:

A function is a block of ordered, portable code used to perform a single, connected operation. The syntax of function declaration can be given as:

Syntax :

returntype functionName(parameter1, parameter2); //function prototype

or declaration

returntype functionName(parameter1, parameter2) //function definition or header of the function  

{  

//function body.

//function implementation

 //return value;

}

In the given question the header of the showDub function is on line 15.

That's why the answer to this question is "15 line".  

8 0
3 years ago
Two strategies for keeping your files in sync
zlopas [31]

Answer:

1. MS Cloud

2. G Drive

Explanation:

5 0
3 years ago
The answer to this question
crimeas [40]

the answer to my appertain is b

6 0
4 years ago
Read 2 more answers
Why is it important to identify where privacy data resides throughout your it infrastructure?
charle [14.2K]
<span>One of the key elements in reducing the attack surface of an IT enterprise is to determine the location and sensitive nature of all data, especially privacy data which if compromised, could result in litigation, financial loss, or customer confidence loss. Additionally, this information is part of the foundation of when drafting a Disaster Recovery or Business Continuity plan.</span>
7 0
4 years ago
Search boxes are used to
soldi70 [24.7K]
My guess would be D.
6 0
3 years ago
Other questions:
  • The process of ensuring that web pages coded with new or advanced techniques still are usable in browsers that do not offer supp
    5·1 answer
  • I have this assignment due TONIGHT BEFORE 10PM! Please help. 50 points for whoever will help!! Here is the assignment.
    7·1 answer
  • A family preservation program director helps design a study that evaluates the effectiveness of her program to keep children liv
    12·1 answer
  • While many myths are harmless, why can myths themselves be dangerous?
    12·1 answer
  • With a DUI charge on a driver’s record ______________.
    10·1 answer
  • Which of the following is not a valid C language<br>int​
    6·1 answer
  • PLEASE HELP ASAP I WILL GIVE BRAINLIEST TO CORRECT ANSWER
    15·2 answers
  • describe how sodium ammonium chloride can be separated from a solid mixture of ammonium chloride and anhydrous calcium chloride​
    15·1 answer
  • As you continue to build the help desk, you want to ensure that all of the tools are in place and that the analysts have the too
    15·1 answer
  • Why is a salt added to a password that is being stored in a database?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!