) Rewrite the following program using macro definitions (#define) for all the co
ID: 1766036 • Letter: #
Question
) Rewrite the following program using macro definitions (#define) for all the constants and a new type definition (typedef) called Card for all the values representing the value of cards. #include int main(void) { char selectedCard; printf(“Choose a card ”); scanf(“%c”, &selectedCard); if (selectedCard == ‘J’ || selectedCard == ‘Q’ || selectedCard == ‘K’) { printf(“You earn 10 points ”); } else if (selectedCard >= ‘5’ && selectedCard <= ‘10’) { printf(“You earn 2 pts ”); } else if (selectedCard == ‘1’) { printf(“You earn 20 pts ”); } else { printf(“No cheating allowed. You earn 0 pts ”); } return 0; } 2. (25 pts) Declare a character array of size 5. Write a loop to initialize the array with consecutive letters starting at the letter 'M' 3. (15 pts) Declare a two dimensional int array of size 3 x 10 (row x column) and initialize the first element of every row to 7 and the remaining elements to 0 at the same time of declaration. 4. (25 pts) Write a function that takes a character as input and returns it in uppercase. If the character is uppercase or not an alphabet letter, the function should return the same character without changing it
Explanation / Answer
1.Answer:
\Code
#include <stdio.h>
typedef enum
{
CARD_I='I',
CARD_J='J',
CARD_Q='Q',
CARD_K='K',
CARD_5='5',
CARD_10='10'
} Card;
int main()
{
CHAR SCard;
printf(" Select Your Card ");
scanf("%c", &SCard);
if(SCard == CARD_J || SCard == CARD_Q || SCard == CARD_K)
printf("Earn 10 points ");
ELSE if(SCard ==CARD_I)
printf("Earned 20 points ");
ELSEIF(SCard >=CARD_5 && SCard <=CARD_10)
printf("Earned 2 points ");
ELSE printf("Cheating not allowed. You earned 0 points ");
return 0;
}
PLEASE RATE ME IF YOU LIKE MY ANSWER
FEEL FREE TO ASK ANY DOUBT
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.