Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> using namespace std; /* Type your code here. */ int intSqrRo

ID: 3857536 • Letter: #

Question

#include <iostream>

using namespace std;

/* Type your code here. */

int intSqrRoot(int num)

{

int sq = 1;// square of count

int count = 1;// increment count every iteraion

cout << "[" << count << "]";// Print intermediate values

while (sq <= num) //until square of count is greater then num

{

count++;

sq = count * count;

if (sq < num)

cout << "[" << count << "]";// Print intermediate values

}

cout << " ";

return count - 1;// previous of final number

}

int main()

{

int num;

cout << "Please enter a number between 2 and 1000: ";

cin >> num;

cout << num << endl;

if ((num < 1) || (num > 1000))

cout << "Please follow the directions!" << endl;

else {

int answer;

answer = intSqrRoot(num);

cout << "The integer square root of ";

cout << num;

cout << " is ";

cout << answer;

cout << ".";

cout << endl;

}

}

12.9 Problem 12.2 Play the rock paper scissors game. Two players enter either rock, paper, or scissors and the winner is determined as follows: paper covers rock rock breaks scissors scissors cut paper s cut paper Ask the user if s/he wants to play again. BE SURE to include a function called play as shown in the template. Sample run: Play rock, paper, scissors Player 1: rock Player 2: paper Player 2 winsPaper covers rock Do you want tcontinue? (yes r no): yes Player 1: scissors Player 2: rock Player 2 wins - Rock breaks scissors Do you want to continue? (yes or no): no NOTE You must include a function called play which plays the game and returns

Explanation / Answer

#include <iostream>

using namespace std;

string play(string a, string b)// return matching string if possible else return No match

{

if (a+" covers "+b == "paper covers rock" || b+" covers "+a == "paper covers rock")// First case

return "paper covers rock";

else if(a+" break "+b == "rock break scissors" || b+" break "+a == "rock break scissors")// Second case

return "rock break scissors";

else if (a+" cut "+b == "scissors cut paper" || b+" cut "+a=="scissors cut paper")// Third case

return "scissors cut paper";

return "No match";

}

void playGame()// Call this function in main

{

cout << "Play rock, paper, scissors ";

string a;

string b;

while(true)

{

cout << "Player 1: ";// Player 1 input

cin >> a;

if(play(a, b) != "No match")// if match hits player 1 wins

{

cout << "Player 1 wins -- " << play(a, b) << " ";

cout << "Do you want to continue? (yes or no): ";

string signal;

cin >> signal;// get yes, no

if (signal == "no")

break;

else

{

a="";// reset strings for further play

b="";

continue;

}

}

cout << "Player 2: ";// Player 2 input

cin >> b;

if(play(a, b) != "No match")// If Match hit player 2 wins

{

cout << "Player 2 wins -- " << play(a, b) << " ";

cout << "Do you want to continue? (yes or no): ";

string signal;

cin >> signal;

if (signal == "no")

break;

else

{

a="";

b="";// reset strings for further play

continue;

}

}

}

}

int intSqrRoot(int num)

{

int sq = 1;// square of count

int count = 1;// increment count every iteraion

cout << "[" << count << "]";// Print intermediate values

while (sq <= num) //until square of count is greater then num

{

count++;

sq = count * count;

if (sq < num)

cout << "[" << count << "]";// Print intermediate values

}

cout << " ";

return count - 1;// previous of final number

}

int main()

{

int num;

cout << "Please enter a number between 2 and 1000: ";

cin >> num;

cout << num << endl;

if ((num < 1) || (num > 1000))

cout << "Please follow the directions!" << endl;

else {

int answer;

answer = intSqrRoot(num);

cout << "The integer square root of ";

cout << num;

cout << " is ";

cout << answer;

cout << ".";

cout << endl;

}

playGame();

}