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

C sharp/ cod blocks stick to the instructions plz best regards Solved: | Chegg.c

ID: 3745907 • Letter: C

Question

C sharp/ cod blocks stick to the instructions plz best regards Solved: | Chegg.com xh Stream TV and Movies Li xConnect-Class: Principle x (27) Lesson su /pid-484099-dt-content-rid-2782342_1/courses/CS-210-01.2018FA 36088/02ProgrammingProject Problem Statement Many students get into computer science to write video games. For this problem, you are to develop a simple computer game that allows two users to play one match of Rock, Paper, Scissors. In the game of Rock, Paper Scissor, players simultaneously choose one of the eponymous elements by flashing a hand gesture and comparin the results. The winner is chosen as follows: Rock beats Scissors (because it breaks them). Scissors beats Paper (because it cuts it). Paper beat Rock (because it covers it and makes it sad). If both players choose the same element, then the match is a tie. Program Specifications For this assignment, you are given the program specification in the form of an analysis and design for a series of functions that must be implemented. Each function accomplishes one task needed for this program. You should write a function and then test it with a main program that ensures that the function works by itself. Once the function is working, move on to the next function, which will require a different main function to test it. Once all of the individual functions work, the final main function that actually will play the game is written. Function: print greeting Analysis: no parameter or returned objects Design: This function's task is simply to print out the greeting at the beginning of the program. See the sample run for the exact text format Function: get_pick Analysis: Objects player's number character user picked converted to uppercase char Type Movement received returned Name int player num ch Design: This function's task is to prompt a user by player number to enter either R for rock, P for paper, or S for scissors and return the character entered in uppercase. Here are the steps to the accomplish this: 1. Ask the user by player number for an input of R, P, or S 2. Convert the input to uppercase 3. Return the input Notes: See the sample run for the exact text format of the prompt. Read the user's input using scant( %c", &ch); Note there is a space before the % symbol. This will make scanf ignore any whitespace before the input. Convert ch to uppercase using the toupper function in the ctype.h library. Don't forget to include the library at the top of your file. The toupper function receives a character argument and returns the uppercase equivalent for alphabetic letters. If the argument is not a letter, it returns the argument . . REMEMBER! Test this function (and all other functions) with a throwaway main function.

Explanation / Answer

#include <stdio.h>

#include <ctype.h>

// function to print greeting message

void print_greeting()

{

printf("Welcome to the RPS Game! Let's play!! ");

}

// function to ask players to pick from rock, paper or scissor

char get_pick(int player_num)

{

char ch;

printf("Player %d, Pick (R)ock, (P)aper, or (S)ciccors:",player_num );

scanf(" %c", &ch);

// checking if the entered value is an alphabet

if (isalpha(ch))

{

// changing to uppercase

ch = toupper(ch);

}

// return the character as it is if its not an alphabet

return ch;

}

// function to print players' choices

void print_picks(char player1, char player2)

{

// checking if player 1 chose other than R, P, or S

if (player1!='R'&& player1!='S'&& player1!='P' )

{

printf("Player 1 chose Unknown " );

}

else if (player1=='R')

{

printf("Player 1 chose Rock ");

}

else if (player1=='S')

{

printf("Player 1 chose Scissors ");

}

else if (player1=='P')

{

printf("Player 1 chose Paper ");

}

// checking if player 2 chose other than R, P, or S

if (player2!='R'&& player2!='S'&& player2!='P' )

{

printf("Player 2 chose Unknown " );

}

else if (player2=='R')

{

printf("Player 2 chose Rock ");

}

else if (player2=='S')

{

printf("Player 2 chose Scissors ");

}

else if (player2=='P')

{

printf("Player 2 chose Paper ");

}

}

// function to compute the winner

int compute_winner(char player1, char player2)

{

// if player 1 chose invalid

if (player1!='R'&& player1!='S'&& player1!='P' )

{

// and if player 2 also chose invalid

if (player2!='R'&& player2!='S'&& player2!='P' )

return 0;

// if only player 1 chose invalid

return 1;

}

// if player 2 chose invalid

// and since player 1 chose valid as checked in above conditions

if (player2!='R'&& player2!='S'&& player2!='P' )

{

return -1;

}

// if both player chose same

if (player2==player1)

{

return 0;

}

// now matching since both are valid picks and not a tie

if (player1=='R')

{

if(player2=='P')

return 1;

return -1;

}

if (player1=='P')

{

if(player2=='S')

return 1;

return -1;

}

if (player1=='S')

{

if(player2=='R')

return 1;

return -1;

}

}

int main()

{

int winner;

char player1,player2;

printf(" ");

print_greeting();

player1 = get_pick(1);

player2 = get_pick(2);

printf(" ");

print_picks(player1,player2);

winner = compute_winner(player1,player2);

if (winner<0)

{

printf("Player 1 wins! ");

}

else if (winner>0)

{

printf("Player 2 wins! ");

}

else printf("Tie!! ");

printf(" ");

return 0;

}