having trouble writing these programs (IN C) int draw_card(int[]); /* Picks the
ID: 3848149 • Letter: H
Question
having trouble writing these programs (IN C)
int draw_card(int[]);
/* Picks the first card that hasn’t been drawn already, marks it as “taken” and returns the value of the card.
Change value to -1 at the location to indicate “taken”
Arguments— int[] deck of cards, which was created in main()
return – int: value of card drawn.
int lucky_seven(int);
/*
Implements lucky seven game logic. Takes in one card value and checks if it is equal to 7.
return 1 if value matches indicating the user won, return 0 if user loses.
Explanation / Answer
code:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int draw_card(int arr[])// it return cards number from 1 to 52
{
int i=0;
while(arr[i]!=0)
{
i++;
}
arr[i]=1;
return i+1;
}
int lucky_seven(int no)
{
if(no==7)
return 1;
else return 0;
}
int main (int argc, char* argv[] ) {
int cards[52];
int i=0;
for(i=0;i<52;i++)
cards[i]=0;//0 indicate not taken and 1 indicate taken
int no = draw_card(cards);
if(lucky_seven(no)==1)
printf("user won");
else
printf("user loss");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.