/* ** e1.c: sample solutions to questions III and IV in Exam#1 ** -- written by Jeff Tian, 10/7/99. */ #include #include "genlib.h" #include "simpio.h" #define N 2 void e1q3_2(); void e1q4(); int GetCard(); main() { printf("CSE 1341-801, Exam#1, Question III, Part 2.\n"); e1q3_2(); printf("\nCSE 1341-801, Exam#1, Question IV.\n"); e1q4(); } /* e1q3_2() ** Note: you need to debug and correct the program.** ** A function to calculate averages of N numbers. ** -- written by Jeff Tian, 9/30/99. ** -- corrected by Jeff Tian, 10/7/99. */ void e1q3_2() { int i, x; double y=0; for (i=1; i<=N; i++) { printf("Enter number %d of %d numbers: ", i, N); x = GetInteger(); y += (double) x/N; } printf("The average of these %d number is %g.\n", N, y); } /* e1q4() -- a function to calculate averages of N numbers. */ void e1q4() { int i, card, strength=0; for (i=1; i<=13; i++) { card = GetCard(); switch(card) { case 1: strength += 4; break; case 11: strength += 1; break; case 12: strength += 2; break; case 13: strength += 3; break; } } printf("The strength of your hand is %d points.\n", strength); } /* GetCard() -- a function to read the next card. */ int GetCard() { int card; printf("Please enter the next card (1-13):"); card = GetInteger(); if (card > 13 || card < 1) { printf("Invalid input. Card must be between 1 and 13. Try again:"); card= GetCard(); } return(card); }