Question

this is a c++ question. just need to do the part that says student code. Complete...

this is a c++ question. just need to do the part that says student code.


Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number.
Sample program:

#include 
using namespace std;

int main() {
   int countLimit = 0;
   int printVal = 0;

   // Get user input                                                            
   cin >> countLimit;

   printVal = 0; 
   do {
      cout << printVal << " ";
      printVal = printVal + 1;
   } while (  );
   cout << endl;

   return 0;
}
"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



Sample program:

#include 
#include 
using namespace std;

int main() {
   string simonPattern;
   string userPattern;
   int userScore = 0;
   int i = 0;
   
   userScore = 0;
   simonPattern = "RRGBRYYBGY";
   userPattern  = "RRGBBRYBGY";

   

   cout << "userScore: " << userScore << endl;

   return 0;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: Note: Given code is modified C+ code: # include«iostream> using namespace std; //Main program int main() //declare vaC+ code: # include«iostream> using namespace std; //main code int main() //Declare variables string simonPattern; string usercode:

1.

C++ code:

#include

using namespace std;

//Main program

int main()

{

//declare variables

int countLimit = 0;

int printVal = 0;

// gets the user inpput

cout<<"Input a positive Number:"<

cin >> countLimit;

//sets private value as 0

printVal = 0;

//do

do

{

//print the value

cout << printVal << " ";

//Assigns the print val

printVal = printVal + 1;

//set value count imit

} while (printVal<=countLimit);

//to print next line

cout << endl;

//To pause the console

system("pause");

return 0;

}

code 2:

#include
using namespace std;
//main code
int main()
{
//Declare variables
string simonPattern;
string userPattern;
int userScore = 0;
int i = 0;
userScore = 0;
//Declares the patterns
simonPattern = "RRGBRYYBGY";
userPattern = "RRGBBRYBGY";
//set pattern length using for loop
for(i=0; i < simonPattern.length(); i++)
{
//check the condition pattern is equal
if(simonPattern[i] == userPattern[i])
{
//Increments the user score
userScore++;
}
//else
else
{
break;
}
}
//Prints the user score
cout << "userScore: " << userScore << endl;
system("pause");
return 0;
}

Answer #2

Answer: Program 1: #include <iostream> using namespace std; int main () int countし1mit = 0; int printval 0; // Get user input//condition is false, exit the loop else break; cout << userScore: << userScore << endl; return 0 Sample Output: sh-4.2$ g+

Editable code:

Program 1:

#include

using namespace std;

int main()

{

int countLimit = 0;

int printVal = 0;

// Get user input

cout<<"Enter positive integer: ";

  

cin >> countLimit;

printVal = 0;

  

do

{

cout << printVal << " ";

printVal = printVal + 1;

} while (printVal <= countLimit);

  

cout << endl;

return 0;

}

Program 2:

#include

using namespace std;

int main()

{

string simonPattern;

string userPattern;

int userScore = 0;

int i = 0;

  

userScore = 0;

simonPattern = "RRGBRYYBGY";

userPattern = "RRGBBRYBGY";

  

//for loop to continue till the length of the simon pattern

for(i=0; i < simonPattern.length(); i++)

{

//condition to check simon pattern and user pattern is equal

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

{

/* condition is true, increment the variable userScore by 1 */

userScore++;

}

//condition is false, exit the loop

else

{

break;

}

}

cout << "userScore: " << userScore << endl;

return 0;

}

Know the answer?
Add Answer to:
this is a c++ question. just need to do the part that says student code. Complete...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CHALLENGE ACTIVITY 4.8.1: Simon says Simon Says" is a memory game where Simon outputs a sequence...

    CHALLENGE ACTIVITY 4.8.1: Simon says 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 1 import java.util.Scanner; 3 public class...

  • "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 import java.util.Scanner;...

  • "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>...

  • Plz use c language "Simon Says" is a memory game where "Simon" Outputs a sequence of...

    Plz use c language "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 user Score Upon a mismatch, exit the loop using a break statement Ex The following patterns yield a user Score of 4: simon Pattern: R, R, G, B, R, Y, Y,...

  • This is a C++ question need to complete project 2. attached the completed simple version of...

    This is a C++ question need to complete project 2. attached the completed simple version of the program below but need the updated version which is listed in the project 2 outline Project 2 Rock, Paper, Scissors Updated Take the solution to Lab 3 and make sure the user enters a letter of R, P, or S and the computer generates a number between 0-2 and changes that number to a letter of R, P or S, using a switch....

  • I need to make a few changes to this C++ program,first of all it should read...

    I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...

  • 15.6: Fix the code to print the count from 1 to x (to loop x times)...

    15.6: Fix the code to print the count from 1 to x (to loop x times) #include <iostream> // include the header file using namespace std; void count(int x){    for(int i=1; i<=x; i++){ cout<<x; } } int main(){    int x,i;    cin >> x; count(x);    return 0; } 15.7 Fix the nested for loops to print the count from 1 to x twice, e.g. "12....x12.....x" #include <iostream> // include the header file using namespace std; int main(){...

  • C++ problem. Please just find and fix the errors and highlight it afterwards. Do not add...

    C++ problem. Please just find and fix the errors and highlight it afterwards. Do not add any new comments or remove comments from teachers. Thank you very much *R 2B PROGRAM 1B: INSERTION SORT Find and rix errors. Ron the program once and save the outpat as a conment at the end of the source file Changed by: IDE #include <iostream> using namespace std: void insertionSort (int aryll, int size) int main double list(1001-(50.1, 30.2, 80.3, 10.5, 30.2, 40.9, 90.8,...

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...

  • Hello, The C++ question is: ------------------------------------------------------------------------------- Write a program that takes as input 2 strings from...

    Hello, The C++ question is: ------------------------------------------------------------------------------- Write a program that takes as input 2 strings from the user. Then it determines if one string is a permutation of the other string. If the program answers "yes" to the previous question, meaning the two strings are permutations of each other, determine if each string has all unique characters. --------------------------------------------------------------------------------- I have completed the first part but I am unsure on how to also determine if each string is all unique characters...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT