Question: I am making a military time program in Pelles C and I need some help to meet these requirements. (I posted this question multiple times

I am making a military time program in Pelles C and I need some help to meet these requirements. (I posted this question multiple times already and the solutions were wrong each time so I will try to make the instructions more specific to what I need)

Learning how to Output data all over the Console Window. Requirements: 1. Create a C program. 2. Display the clock on row 3, col 20. The clock format will be as follows: [ 0 : 00: 00 ] 3. Loop thru all of the seconds in the day, from 0:0:0 to 23:59:59. 4. Have the user hit any key to start the clock. 5. The clock will sleep after displaying each second. The initial sleep time will be 100ms. 6. By hitting keys, the user will be able to change the sleep time anywhere between min: 100ms to max: 2000ms. 7. In real time, detect, these keystrokes: a. + : This will increase the sleep time by 100ms. Do not go over the maximum limit. b. - : This will decrease the sleep time by 100ms. Do not go below the minimum limit. c. : will exit the program. Move the cursor to bottom of console window before exiting. d. F5 : Start the clock over at 0:0:0. e. If any other key is hit, go to row 1, col 50 to display this invalid keystroke. 8. The program will end by 1 of 2 ways: a. It loops thru all of the seconds in a day. b. User hits

Programming Tips 1. You MUST use nested WHILE loops.

My code so far (I want to build off of this code, NOT completely start over):

IMPORTANT FOR SOLUTION:

- So far, I got the clock to work in a loop and a few keystrokes to work (but they are NOT correct by any means. They need to work more in accordance with the requirements)

- Do not include any other libraries besides the ones I am providing, because Pelles C will not recognize certain file types (So please keep the solution code as simple as possible for these requirements)

- No break or exit statements (The ones in my code will need to be fixed)

#include #include #include

int hour=0,minute=0,second=0,flag=0; //global variables

void delay(ms) //delay function { clock_t timeDelay = ms + clock(); //Step up the difference from clock delay while (timeDelay > clock()); //stop when the clock is higher than time delay } int counter(){ while(!_kbhit() && flag ==0){ //keep looping while the user didn't hit any key and flag is 0 if (hour >23) { hour = 0; }

if(minute > 58) { //after minute is greater than 59, reset minute and increase 1 hour minute = 0;++hour; }

if(second > 59) { //after second is greater than 59, reset second and increase 1 minute second = 0;++minute; } printData(); //print out the new data, delay for 1000 millisecond and increase 1 second. delay(1000);second += 1; } selection(); //after the user hit the keyboard, call the menu selection }

int printData(){ //print data to screen system("cls"); //clear the screen printf("1.Start 2.Stop 3.Reset 4. End "); //menu for user printf("*********************************** "); printf(" [%d:%d:%d] ",hour,minute,second); //output the data printf("*********************************** "); }

int selection(){ // menu selection switch(_getch()){ //collect input from user case 49: flag =0; break; //press 1 set flag to 0 means start case 50: flag =1; break; //press 2 set flag to 1 means stop case 51: hour = minute = second = 0;flag = 1; //press 3 reset everything, set flag to 1 means stop printData(); //print the new data after reset break; case 52: exit(0);;break; //press 4, exit the program } }

int main() { while(1){ //keep the program running and never end counter(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!