In-Class Practice

Logic Constructs

Selection Constructs

Card Decks

A card deck consists of 52 cards: 13 in each of 4 suits.  The rank of a card in any suit ranges from 2 tthrough 10, Jack, Queen, King and Ace. In some card games, a numbered card is worth its face value, the Jack, Queen and King, are each worth 11 points and the Ace is worth 1 point.

Specification

Complete the following program that accepts the rank of a card and displays the value of that card.  The user enters '0' for the number 10 card.  The card suit does not matter here.  Use an if else construct for your first version.

 ``` // Card Value // cardValue.c int main(void) { char rank; int points; printf("Enter the card rank : "); scanf("%c", &rank); printf("The value of the card is %d points\n", points);  }```

Write a second version of the program that performs the same valuation, but uses a switch construct.

 ``` // Card Value // cardValue.c int main(void) { char rank; int points; printf("Enter the card rank : "); scanf("%c", &rank); printf("The value of the card is %d points\n", points);  }```

Iteration Constructs

An arithmetic series is a sequence of positive integers from 1 until a terminal value; for example, 1, 2, 3, 4, ..., 8, 9.  Write a program that accepts the terminal value and displays the sum of the series up to and including the terminal value.

For your first version, use a while construct.

 ``` // Arithmetic Series // series.c int main(void) { int terminal, sum; printf("Enter the terminal integer : "); scanf("%d", &terminal); printf("The sum of the series is %d\n", sum);  }```

For your second version use a for construct.

 ``` // Arithmetic Series // series.c int main(void) { int terminal, sum; printf("Enter the terminal integer : "); scanf("%d", &terminal); printf("The sum of the series is %d\n", sum);  }```