Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 or incomplete)

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.

IMPORTANT FOR SOLUTION:

- Do not include any other libraries besides the ones mentioned below, 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.

- Use _kbhit to activate the different keystrokes (my keystrokes don't work right currently).

My code so far:

#include #include #include

int main() { int hour = 0, minute = 0, second = 0, sleep_time = 100; printf("Press any key to start "); getchar();

while (hour < 24) { while (minute < 60) { while (second < 60) { system("cls"); printf("\033[3;20H[%02d:%02d:%02d]", hour, minute, second); fflush(stdout);

int key = getchar(); if (key == '+') { sleep_time += 100; sleep_time = sleep_time > 2000 ? 2000 : sleep_time; } else if (key == '-') { sleep_time -= 100; sleep_time = sleep_time < 100 ? 100 : sleep_time; } else if (key == 27) { printf("\033[100;1H"); return 0; } else if (key == 0x3F) { hour = 0; minute = 0; second = 0; } else if (key != ' ') { printf("\033[1;50HInvalid Key: %c", key); }

Sleep(sleep_time); second++; } second = 0; minute++; } minute = 0; hour++; }

return 0; }

(A revised version of my code would be greatly appreciated, and preferably one without errors when I copy it into Pelles C)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

c. Acafeteriawhere healthy, nutritionally balanced foods are served

Answered: 1 week ago