I. Learner Objectives: At the conclusion of this programming assignment, partici
ID: 3705752 • Letter: I
Question
I. Learner Objectives: At the conclusion of this programming assignment, participants should be able to: * Declare and define arrays of pointers to strings Manipulate 2-Dimensional arrays Apply triply nested loops Manipulate strings I. Prerequisites: Before starting this programming assignment, participants should be able to Apply and implement pointers in C Pass output parameters to functions Analyze a basic set of requirements and apply top-down design principles for a problem Apply repetition structures within an algorithm Construct while , for ), or do-while loops in C Compose C programs consisting of sequential, conditional, and iterative statements Eliminate redundancy within a program by applying loops and functions *Create structure charts for a given problem Open and close files * Read, write to, and update files Manipulate file handles Apply standard library functions: fopen (), fclose (), fscanf (), and fprintf () Apply and implement pointers 2-dimenional arrays Define and apply structs in C Compose decision statements if conditional statements) Create and utilize compound conditions Summarize topics from Hanly & Koffman Chapter 8 including What is an array? Distinguishing between single dimensional and 2-dimentional arrays What is an index III. Overview & Requirements: Write a program that allows a user to play 5-Card-Draw Poker against the computer, Start with the following example code supplied by Deitel & Deitel (example code). This will help you get started with the game of Poker. Please read this site to learn the rules of Poker http://en wikipedia.org/wiki/5_card draw. Complete the following step and you will have a working Poker game!!! Adapted from Deitel &Deitel;'s C How to Program (6th Edition):Explanation / Answer
Solution:
code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void score();
int main()
{ void gamerules();
void game();
int choice;
int i=1;
do{
printf("***MENU*** 1.Print the rules 2.Start a new Game 3.Exit Enter one of the input value (1,2,3) :");
scanf("%d",&choice);
system("cls");
switch(choice)
{
case 1: gamerules();break;
case 2: game();break;
case 3: printf("Goodbye from the game ");exit(0);
}
i=choice;
}while(i!=1||i!=2);
}
void gamerules()
{
//you can write the rules on your own
}
void game()
{
int dice[5];int count=0,i;int move;int ch;int verify[13]={0};int rrl;int ch1;
printf("press any key (0-9) to roll the dice ");
scanf("%d",&move);
for(i=0;i<5;i++)
dice[i]=rand()% 6 + 1 ;
printf("face value of each dice 1-->%d 2-->%d 3-->%d 4-->%d 5-->%d ",dice[0],dice[1],dice[2],dice[3],dice[4]);
count++;
printf("select one of the combination ");
printf("1.Sum of 1's 2.Sum of 2's 3.Sum of 3's 4.Sum of 4's 5.Sum of 5's 6.Sum of 6's 7.Three of a kind 8.Four of a kind 9.Fullhouse 10.Small straight 1.Large straight 12.Yahtzee 13.Chance ");
scanf("%d",&ch1);
do
{
printf("if you want to use the roll for combination-- press 0/1 ? ");
scanf("%d",&ch);
if(ch==1)
select_combination(ch1,dice,verify);
else if(ch==0)
{
printf("which dice u want to re-roll (1-5)");
count++;
for(i=0;i<5;i++)
{
printf("want to re-roll dice %d press 0/1 ?",i+1);
scanf("%d",&rrl);
if(rrl==1)
dice[i]=rand()%6+1;
}
printf("face value of eacj dice 1-->%d 2-->%d 3-->%d 4-->%d 5-->%d ",dice[0],dice[1],dice[2],dice[3],dice[4]);
}
}while(count!=3&&ch==0);
}
void select_combination(int ch,int* dice,int* verify)
{
if(verify[ch-1]==0){
verify[ch-1]=1;score(dice,ch);
}
else
{
printf("combination used ");
score(0);
}
}
void score()
{
//as no details is told about scoring part,,,,it is left to user
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)