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

This is for C Programming: I have the folloiwng assignment I am working on and h

ID: 3735898 • Letter: T

Question

This is for C Programming: I have the folloiwng assignment I am working on and have ABSOLUTELY NO CLUE how to set up the next function. Please help! I am not sure how to approach creating the functions for the following assignment.

This is the assignment:

Please choose an option to continue:

When a player chooses to play a new game, the computer will create a new deck of cards, shuffle it and deal seven cards to each player. The player always goes first, so the program will then print the player’s hand and give the player options for viewing the player’s books, the computer’s books, or making a guess:

Your Hand:

two clubs

eight hearts, eight diamonds

jack spades, jack diamonds, jack hearts

king clubs

1. Make a guess

2. View your books

3. View computer’s books

Please choose an option to continue:

If the player chooses to make a guess, the computer should ask the player what rank they wish to guess. The player should enter a string, either “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”, “ten”, “jack”, “queen”, “king”, or “ace” (without the quotes). One technique then that you can use to determine which selection was made is to have an array of strings with all of

the ranks in it. The ranks should be in this array in the same order that they are in the enum for ranks.

This is my code so far:

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

#include <string.h>

void welcomeGoFish(void)

{

printf("--------------------WELCOME TO GO FISH!---------------------- ") ;

printf("--Objective is to collect as many 'books' as possible.------- ");

printf("--A book is four cards of the same rank. ----------------- ");

printf("--The player with the most books at the end of the game--- ");

printf("--wins.---------------------------------------------------- ");

printf(" ");

}

int gameChoice()

{

int choice;

printf("Welcome to Go Fish! ");

printf("1. Play a new game 2. Exit the program ");

printf("Select one of the options: 1 or 2: ");

scanf("%d",&choice);

if(choice == 1 || choice == 2){

return choice;

}

else{

return -1;

}

}

int main(int argc, char **argv)

{

welcomeGoFish();

printf("%d ",gameChoice());

printf("%d ",gameChoice());

printf("%d ",gameChoice());

return 0;

}

Explanation / Answer

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

#include <string.h>

void welcomeGoFish(void)
{
printf("--------------------WELCOME TO GO FISH!---------------------- ") ;

    printf("--Objective is to collect as many 'books' as possible.------- ");

    printf("--A book is four cards of the same rank. ----------------- ");

    printf("--The player with the most books at the end of the game--- ");

    printf("--wins.---------------------------------------------------- ");

    printf(" ");

}

int gameChoice() {

   int choice;

   printf("Welcome to Go Fish! ");

   printf("1. Play a new game 2. Exit the program ");

   printf("Select one of the options: 1 or 2: ");

   scanf("%d",&choice);

   if(choice == 1 || choice == 2){

       return choice;

   }

   else{

       return -1;

   }

}

void newGame() {
   char number[][15] = {"two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king", "ace"};
   char card[][15] = {"clubs","diamonds","spades","hearts"};
   printf("Your Hand: ");
   int total_card = 7;
   while(total_card--) {
       int n = rand() % 13 ;
       int m = rand() % 4;
       printf("%s %s ",number[n],card[m]);
   }
   printf("----1. Make a Guess ---- ");
   printf("----2. View Player's book ---- ");
   printf("----3. View Computer's book ---- ");
   int opt;
   char str[15];
   scanf("%d",&opt);
   switch(opt) {
       case 1 :
           printf("what rank you wish to guess ? ");
           scanf("%s",str);
           printf("You guess rank : %s ",str);
           break;
       case 2 :
           printf("I am in Player's book ");
           break;
       case 3 :
           printf("I am in Computer's book ");
           break;
       default :
           printf("Invalid Option ");
   }
}

int main() {

welcomeGoFish();
while(1) {
   if(gameChoice()==1) {
       newGame();
   }
   else {
       exit(1);
   }
}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote