Write a shuffle program to randomize the deck of cards

Assignment Help Programming Languages
Reference no: EM132211706

Question: (Write a program, and show the output too) C programming

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int main ( )

{

// card is an array with 24 cells, each cell is of type char pointer

// The strings are constant, the address of the first character

// is constant and can't be changed.

// we assign that address to the cells in the array

// This is similar to char *p = "Sample String" ;

char *card[24] = {

"spade-one",

"spade-two",

"spade-three",

"spade-four",

"spade-five",

"spade-six",

"heart-one",

"heart-two",

"heart-three",

"heart-four",

"heart-five",

"heart-six",

"diamond-one",

"diamond-second",

"diamond-three",

"diamond-four",

"diamond-five",

"diamond-six",

"club-one",

"club-two",

"club-three",

"club-four",

"club-five",

"club-six"

} ;

int i ;

// Write A shuffle program to randomize the deck of cards

// so each player will get different cards.

// Question1: TRACE THIS CODE FOR AT LEAST FIVE ITERATIONS

// WHAT AM I DOING ?

// WHAT AM I SWAPPING , VALUES, ADDRESSES?

// GIVE AS MUCH AS DETAILS AS POSSIBLE

srand( time ( NULL ) );

for ( i = 0 ; i < 24 ; i++ )

{

char *temp ;

int cardNo = rand( ) % ( 24 - i ) ;

temp = card [ cardNo ] ;

card [ cardNo ] = card [ 24 - i - 1 ] ;

card [ 24 - i - 1 ] = temp ;

}

printf ( "\n Printing the cards of player 1 \n" );

for ( i = 0 ; i < 24 ; i+=4 )

{

printf ( " %s \n", card [ i ] );

// add code to check if player 1 has three6s

}

printf ( "\n Printing the cards of player 2 \n" );

for ( i = 1 ; i < 24 ; i+=4 )

{

printf ( " %s \n", card [ i ] );

// add code to check if player 2 has three 6s

}

printf ( "\n Printing the cards of player 3 \n" );

for ( i = 2 ; i < 24 ; i+=4 )

{

printf ( " %s \n", card [ i ] );

// add code to check if player 3 has three 6s

}

printf ( "\n Printing the cards of player 4 \n" );

for ( i = 3 ; i < 24 ; i+=4 )

{

printf ( " %s \n", card [ i ] );

// add code to check if player 4 has three 6s

}

// repeat the above code if any player has three 1s

}

Compile and run the above. Try to understand how I distributed the cards to the four players.

As you can see, we are printing the cards of each player.

if you want to search for a player who has a six, you could do

if ( strstr ( card [ i ] , "six" ) != NULL )

statement, right ? Here, strstr returns NOT NULL if "six" is a substring of card [ i ] .

Using the above fact, add code to find the winner. The winner is the player who has at least three 6s. Print all cards of the winner.

If you can't find any player with three 6s, then search for a player who has least three 1s . Print all cards of the winner

If you can't find any player, then don't do anything, exit the program stating no winner found.

You may have to run your program several times before you find a winner because the probability of finding a winner is very low. So Be Patient.

Reference no: EM132211706

Questions Cloud

Write a program to reverse which display all the elements : Write a program "Reverse" which display all the elements in the array in reverse order, (use multiple print statements).
Calculate the value of a European call option : Using the Black-Scholes option pricing model, calculate the value of a European call option on S&P500 under the following parameters
Describe impacts of and ramifications for organizational : Research Paper Assignment: Describe the impacts of, and ramifications for Organizational structure, change and development.
Describe how to manage termination and retention : Describe how to manage termination and retention.
Write a shuffle program to randomize the deck of cards : Write A shuffle program to randomize the deck of cards. so each player will get different cards. TRACE THIS CODE FOR AT LEAST FIVE ITERATIONS.
Calculate the total amount you would have to pay : The bond dealer's current ask yield to maturity is 3.80 percent. Calculate the total amount you would have to pay for this bond
The internal and external drivers of change experienced : Evaluate how the internal and external drivers of change experienced by GE had affected leadership, individuals and team behaviour within the businesses;
What benefit did medicare obtain by changing the structure : Medicare changed payments to hospitals from cost based to DRG in 1983. What benefit or risk did Medicare obtain by changing the payment structure?
What are the likely consequences of the act : What are the likely consequences of the act? You can adopt one of the viewpoints expressed above or develop another.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd