Code:
int displayClock(int * optionStats, int h, int m)
{
char clock[9][20] = { /* The array to hold the hard-coded clock */
" 12 ",
" 11 01 ",
" 10 02 ",
" ",
"09 . 03 ",
" ",
" 08 04 ",
" 07 05 ",
" 06 "
};
/* Row and column numbers in clock array for hour positions. For
* example, the "06" in the clock display is stored at position
* [8, 8] in the clock matrix (see above) */
const int hr[13] = {0, 1, 2, 4, 6, 7, 8, 7, 6, 4, 2, 1, 0};
const int hc[13] = {0, 13, 15, 16, 15, 13, 8, 3, 1, 0, 1, 3, 8};
/* Hour and minute codes */
const char hs = 'H', ms = 'm';
int i, j; /* Declare other variables as needed */
int a, b;
/* The next 5 comments require code to be developed by you! */
/* Ensure that h and m are in range and, if not, return
* appropriate error value. Otherwise adjust h if it is 0 or it
* exceeds 12
*/
if(h>12 || h<1)
{
printf("Hours is invalid 1 - 12\n");
return FALSE;
}
if(m<0 || m>=60)
{
printf("Minutes is invalid 0 - 60\n");
return FALSE;
}
/* Now update the clock array accordingly, with the hour symbol */
/* Round m to the nearest hour position */
/* Update clock with minute symbol, taking into account a "clash"
* with the hour symbol
*/
for(a=0; a<9; a++)
{
for(b=0; b<19; b++)
{
clock[hr[h]][hc[h]] = hs;
clock[hr[h]][hc[h]+ 1] = hs;
}
clock[hr[m]][hc[m]] = ms;
clock[hr[m]][hc[m]+ 1] = ms;
}
/* Display the clock */
for (i = 0; i < 9; i++)
{
for (j = 0; j < 19; j++)
printf("%c", clock[i][j]);
printf("\n");
}
printf("\n");
return 0;
}