Question: Intensive Programming ================== # passByReference.c #include /* void func(int a, int b) { a += b; printf(func: a = %d b = %d , a,

Intensive Programming

Intensive Programming ================== # passByReference.c #include /* void func(int a, int b)

{ a += b; printf("func: a = %d b = %d ",

a, b); } void main() { int x = 5, y =

==================

# passByReference.c

#include  /* void func(int a, int b) { a += b; printf("func: a = %d b = %d ", a, b); } void main() { int x = 5, y = 7; func(x, y); printf("main: x = %d y = %d ", x, y); } */ void func(int *a, int *b) { *a += *b; printf("func: a = %d b = %d ", *a, *b); } void main() { int x = 5, y = 7; func(&x, &y); printf("main: x = %d y = %d ", x, y); }

Task: Write a C program to play Mastermind against a human codebreaker. Mastermind is a simple two-player code-breaking board game. In the game, one player is the codemaker and the other is the codebreaker. The codemaker secretly selects a code consisting of an ordered sequence of four colors (c1, c2, c3, ca), each chosen from a set of six possible colors, with repetitions allowed. The codebreaker then tries to guess the code by repeatedly proposing a sequence of colors (g, g2, g3, ga). After each guess, the codemaker tells the codebreaker two numbers (b, w): the number of correct colors in the correct positions (b) and the number of colors that are part of the code but not in the correct positions (w) For example, consider the six colors: Blue, Green, Orange, Purple, Red, and Yellow. If the code is (B, G, 0, 0) and the codebreaker's guess is (O, G, P, 0), then the codemaker's response would be (2, 1), since the codebreaker has guessed the G and the second O correctly and in the correct positions, while having guessed the first O correctly but in the wrong position The codebreaker continues guessing until either the codebreaker guesses the code correctly or until twelve incorrect guesses are made Additio nal Specifications: The code to be guessed should be given as a command-line argument Use standard input and standard output only The input/output must exactly match the samples given, character for character Deliverables: A file named mastermind.c containing the ANSI C source code. The submission will not receive a grade if the file mastermind.c produces compilation warnings or errors. So, before submitting your solution, make sure it compiles cleanly using the gcc compiler as follows: $. gcc -ansi -Wall -Wextra -Werror mastermind . c Input/Output Sample 1 $ ./a.out PORG Available Colors: (B)lue (G) reen (0)range (P)urple (R)ed (Y)ellow No. guesses left: 12 Enter your guess: BB00 Feedback: 0, 1 No. guesses left: 11 Enter your guess: BBGG Feedback: 1, No. guesses left: 10 Enter your guess: OPPG Feedback: 1, 2 No. guesses left: 9 Enter your guess: OPYG Feedback: 1, 2 No. guesses left: 8 Enter your guess: PORG Feedback: 4, 0 YOU WIN! Input/Output Sample 2 $ ./a.cut PORG Available Colors: (B)lue (G)reen (0)range (P)urple (R)ed (Y)ellow No. guesses left: 12 Enter your guess BBBB Feedback: , 6 No. gues ses left: 11 Enter your guess: GGGG Feedback: 1, 0 No. guesses left: 18 Enter your guess: 0000 Feedback: 1, E No. guesses left: 9 Enter your guess: PPPP Feedback: 1, 0 No. gues ses left: 8 Enter your guess: RRRR Feedback: 1, No. guesses left 7 Enter your guess: YYYY Feedback: 0, 0 No. guesses left: 6 Enter your guess: GOPR Feedback: 1, 3 No. guesses left 5 Enter your guesS: OGPR Feedback: e, 4 No. guesses left: 4 Enter your guess: PGOR Feedback: 1, 3 No. guesses left: 3 Enter your guess: GPOR Feedback: e, 4 No. gues ses left: 2 Enter your guess: OPGR Feedback: 0, 4 No. guesses left: 1 Enter your guess: POGR Feedback: 2, 2 YOU LOSE! The code is PORG

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!