Question

In: Computer Science

Hi I started writing this program but is confusing the heck out of me and I...

Hi I started writing this program but is confusing the heck out of me and I don't know if I'm just over thinking it too much. Can anyone help me with this? Write a program in c language: simulates a time clock does nested for loops with one switch statement. Declares variables hours, minutes, seconds as integers. For hours are zero to < 24 however switch when hours are greater than 24 print on new line “25 error” switch when hours are thirteen break switches otherwise by default print on new line “top of the hour!” , For minutes are zero to 60, For seconds are zero to 60 in this loop print on a line hours value separated by a colon character minutes value separated by a colon character seconds value with new line character. Just before ending print on new line “Program finished!” then terminate program.

Solutions

Expert Solution


#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>

int main()
{
    int hour=0;
    int min=0;
    int sec=0;

    while(1)
    {
        system("clear");

        printf("%02d : %02d : %02d \n",hour,min,sec);
       
        fflush(stdout);
        sec++;

        if(sec==60){
            min+=1;
            sec=0;
        }
        if(min==60){
            hour+=1;
            min=0;
        }
        if(hour==24){
            hour=0;
            min=0;
            sec=0;
        }
        if (hour>24)
        {
            printf("25 error");
        }
        printf("Program finished! \n");
       
        sleep(1);
    }
    return 0;
}


Related Solutions

Managerial Accounting Project 6 Capital Budgeting Hi, please solve this for me. I'm having one heck...
Managerial Accounting Project 6 Capital Budgeting Hi, please solve this for me. I'm having one heck of a time figuring out these answers. Please show the process on how you got these answers. Thanks!! Carrington Co is a mid-sized financial services firm with small offices throughout the United States. Management is considering the best way to invest cash that has been set aside for technology improvements. They have narrowed their decision down to two options. Option #1 Moving to the...
I need someone to describe these topics to me as the web makes it confusing. Thank...
I need someone to describe these topics to me as the web makes it confusing. Thank you. Money and financial banking. Monetary policy. The federal reserve. Functions of the federal reserve.
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want to plot a 3D animated orbit which is a 60 by 58 nautical miles orbit. Can you provide a code or some idea of how to plot an orbit like this in 3D?
Hi, I can't figure out this question in excel, can someone please show me the excel...
Hi, I can't figure out this question in excel, can someone please show me the excel formulas to input in order to solve for part A and B please!!!! The following table contains closing monthly stock prices for Oracle Corporation (ORCL), Microsoft Corporation (MSFT), and NVidia (NVDA) for the first half of 2017. Ticker 6/30/2017 5/31/2017 4/30/2017 3/31/2017 2/28/2017 1/31/2017 ORCL 50.14 45.39 44.96 44.61 42.59 40.11 MSFT 68.93 69.84 68.46 65.86 63.98 64.65 NVDA 144.56 144.35 104.3 108.93 101.48...
I am writing a shell program in C++, to run this program I would run it...
I am writing a shell program in C++, to run this program I would run it in terminal like the following: ./a.out "command1" "command2" using the execv function how to execute command 1 and 2 if they are stored in argv[1] and argv[2] of the main function?
hi i need a code that will give me this output, For the multiply_list, the user...
hi i need a code that will give me this output, For the multiply_list, the user will be asked to input the length of the list, then to input each element of the list. For the repeat_tuple, the user is only asked to enter the repetition factor, but not the tuple. Your program should take the list created before and convert it to a tuple. output expected: (**user input**) ******Create your List ****** Enter length of your list: 3 ******...
I'm writing a program using EasyReader class. The program wil give me the how much money...
I'm writing a program using EasyReader class. The program wil give me the how much money is left. e.g. someone paid 50 pounds for their 20 pounds worth of groceries so the output will be 30 pounds. my question is, I want it to print out how the change should be made up. how many 10 pounds, 5 pounds, 2 pound and so on, is in the change. how should I write the program
Hi... I have a proposal to do and I'm writing about ( Hospital management system )...
Hi... I have a proposal to do and I'm writing about ( Hospital management system ) so I have a part about ( Motivation for the research) I need someone to write it.
I am writing this machine learning code (classification) to clssify between two classes. I started by...
I am writing this machine learning code (classification) to clssify between two classes. I started by having one feature to capture for all my images. for example: class A=[(4295046.0, 1), (4998220.0, 1), (4565017.0, 1), (4078291.0, 1), (4350411.0, 1), (4434050.0, 1), (4201831.0, 1), (4203570.0, 1), (4197025.0, 1), (4110781.0, 1), (4080568.0, 1), (4276499.0, 1), (4363551.0, 1), (4241573.0, 1), (4455070.0, 1), (5682823.0, 1), (5572122.0, 1), (5382890.0, 1), (5217487.0, 1), (4714908.0, 1), (4697137.0, 1), (4737784.0, 1), (4648881.0, 1), (4591211.0, 1), (4750706.0, 1), (5067788.0, 1),...
I need someone to create a program for me: Create a program that takes as input...
I need someone to create a program for me: Create a program that takes as input an employee's salary and a rating of the employee's performance and computes the raise for the employee. The performance rating here is being entered as a String — the three possible ratings are "Outstanding", "Acceptable", and " Needs Improvement ". An employee who is rated outstanding will receive a 10.2 % raise, one rated acceptable will receive a 7 % raise, and one rated...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT