I am working on a project in class in intro c programming. I have attached at bo
ID: 3664617 • Letter: I
Question
I am working on a project in class in intro c programming. I have attached at bottom my start of code. I am struggling a bit.
6.Create 2 variables, char for suit and int for card value.........Done
7.Assign suit and card value to 2.......Done
8.Now create a for loop that counts from 0 to 52.......Done (But I don't know if I am supposed to split them out by suit?)
9.For each iteration, print the char format of the suit and the int value of the card you declared earlier.
10.Have every iteration increment card value by 1 and if the card value is above 14, reset back to 2.
11.For every time the card value is reset back to 2, have the card suit increment by 1.
12.Now create a function to print the card, suit symbol and card value, but make sure to print J instead of 11, Q instead of 12, K instead of 13.(J not 11)
13. Replace the print calls in the for loop iterations with the new print card function.
14.compile and run program.
Thank you for your help in adavance.
// This is our standard input/output library
#include <stdio.h>
// Declaration
char cSuit = 2;
int nCardValue = 2;
// Function names
// Our main function(entry program point)
int main(void)
{
for (nCardValue = 2; nCardValue <= 52; nCardValue++)
printf("%d ",nCardValue);
printf(" ");
return (0);
}
Explanation / Answer
// This is our standard input/output library
#include<stdio.h>
void printCard(int cardNumber, char cSuit) {
if(cardNumber == 10){
printf("Card value: %d and suit value: 10 ",cardNumber); // since we can not store 2 digit in a char variable
}else{
printf("Card value: %d and suit value: %c ",cardNumber,cSuit);
}
}
int main(void){
// Declaration
char cSuit = '1';
int nCardValue = 1;
int counter;
for(counter = 1; counter <= 56; counter++) { // since we are not considering first card(1), we have only (54-4 = 48) cards
// since we have to also ignore 1 value of each card, so iteration till 56
if(counter % 14 == 0 || counter % 14 == 1){
cSuit = '2';
nCardValue = 2;
continue;
}
if(nCardValue == 11)
cSuit = 'J';
if(nCardValue == 12)
cSuit = 'Q';
if(nCardValue == 13)
cSuit = 'K';
printCard(nCardValue,cSuit);
nCardValue++;
cSuit++;
}
printf(" ");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.