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

  Program to simulate the operation of the simmac

CISC 640 - OS Problem Set - Write three programs in the machine language of the SIMMAC that will total the numbers stored in 20 different locations and place the result in a single location.

  Prolog program to reads employee-s number

Write a prolog program that reads an employee's number from the keyboard, number of hours worked and an hourly rate of pay.

  Write a program that reads an input line from the user

Write a program that reads an input line from the user (until the new-line character \n) and displays the number of times each lower-case letter appears in it (Everything else in the input except lower-case letters can be ignored.)

  Write a class player contain attributes for player

write a class player contain attributes for the player name average and team.write three functions to input change and display these attributes.also write a constructor that asks for input initilize all the attributes?

  Design a real time flood monitoring system

Assignment 3: Design a Real Time Flood Monitoring System based on Arduino Microcontroller. The system should monitor flood related information like Water level and Precipitation. The data collected from the sensors should be transferred to a client a..

  Write a machine-language program

Write a machine-language program to input two one-digit numbers add them, and output the one-digit sum. Write it in a format suitable for the loader and execute it on the Pep/8 simulator.

  Create a program that allows user to enter sets of integer

Create a program that allows the user to enter sets of integer values, in any order.Per set of data,the program is to output the largest number.

  Write a ruby program with the following specification

The second smallest number in the list, along with its position in the list, with 1 being the position of the first number.

  Modify the pseudocode and optimize it.

Provide valid reasons why the pseudocode is now more efficient.

  Write a query to confirm that the changes have taken effect

write the SQL command to add a new redo log group with two members

  Create a class diagram and define the classes

Completed class diagram should show each object's encapsulated methods, the inheritance between subject and course, and the composition of students in courses.

  Discuss the linux process

Displaying Linux Processes (Optional) Time Required: 10 minutes Objective: View processes running in Linux.

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