Question

In C language Write a program that: simulates a time clock does nested for loops with...

In C language

Write a program that: 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 newline
“25error” 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.

Homework Answers

Answer #1

#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");
        }
        if (hour == 13)
        {
            printf("Top of the hour!");
        }
        printf("Program finished! \n");
     
        sleep(1);
    }
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Summary In this lab, you add nested loops to a Java program provided. The program should...
Summary In this lab, you add nested loops to a Java program provided. The program should print the letter E. The letter E is printed using asterisks, three across and five down. Note that this program uses System.out.print("*"); to print an asterisk without a new line. Instructions Write the nested loops to control the number of rows and the number of columns that make up the letter E. In the loop body, use a nested if statement to decide when...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour...
Write a C++ program that converts time of day from a 24-hour notation to a 12-hour notation. For example, it should convert 14:25 to 2:25 PM. (A) The user provides input as two integers separated by ‘:’. The following function prototype should capture the user inputs as described below: void input(int& hours24, int& minutes); //Precondition: input(hours, minutes) is called with //arguments capable of being assigned values. //Postcondition: // user is prompted for time in 24 hour format: // HH:MM, where...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the...
Description: In this assignment, you need to implement a recursive descent parser in C++ for the following CFG: 1. exps --> exp | exp NEWLINE exps 2. exp --> term {addop term} 3. addop --> + | - 4. term --> factor {mulop factor} 5. mulop --> * | / 6. factor --> ( exp ) | INT The 1st production defines exps as an individual expression, or a sequence expressions separated by NEWLINE token. The 2nd production describes an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT