Question

IN C WITH COMMENTS PLEASE, THANKS! Write the void function, convertTime(), which converts a time given...

IN C WITH COMMENTS PLEASE, THANKS!

Write the void function, convertTime(), which converts a time given in only seconds to the associated number of hours, minutes, and remaining seconds. For example, 20,565 seconds is converted to 5 hours, 42 minutes, and 45 seconds. Note: the template does not include the required function prototype, so careful attention must be given to the following instructions to ensure you have the correct format for the function. The function does not return any quantity directly. Instead, the function must have four parameters, in the following order:

  • an integer representing the input total number of seconds
  • a pointer to an integer representing the output number of hours
  • a pointer to an integer representing the output number of minutes
  • a pointer to an integer representing the output number of seconds
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program

#include<stdio.h>
void convertTime(int,int*, int*,int*); /*function prototype*/
int main()
{
      
int seconds,hours, min,sec;
              
printf("Enter an amount of seconds: ");//Input time in seconds
scanf("%d", &seconds);

convertTime (seconds, &hours, &min,&sec);//Function call

//Print Results
printf("The equivalent of %d seconds is %d hours, %d minutes, and %d seconds.\n", seconds, hours, min, sec);   
return 0;
}
void convertTime(int sec, int *h, int *m,int *s)
{

*h = (sec/3600);//Converting to hours

*m= (sec-(3600* *h))/60;//Converting to minutes

*s= (sec -(3600**h)-(*m*60));//Converting to seconds
}

Output

Enter an amount of seconds: 20565
The equivalent of 20565 seconds is 5 hours, 42 minutes, and 45 seconds.


Enter an amount of seconds: 3666
The equivalent of 3666 seconds is 1 hours, 1 minutes, and 6 seconds.

Add a comment
Know the answer?
Add Answer to:
IN C WITH COMMENTS PLEASE, THANKS! Write the void function, convertTime(), which converts a time given...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Write a C function that iterates through a singly linked list and converts it to a...

    Write a C function that iterates through a singly linked list and converts it to a doubly linked list. Your solution must NOT create a second list. You must come up with the appropriate parameters and return type. Note: the nodes in the singly linked list have a field for a previous pointer, but that field has not initially been set in any of the nodes. You must do this as part of your solution!

  • C please In this question, you will find the difference between two time durations. You are...

    C please In this question, you will find the difference between two time durations. You are given the following struct definitions: typedef struct _duration { int hours; int minutes; } Duration; Design a function to find the difference between two durations: Duration* subtract(Duration* duration1, Duration* duration2) { } Return a pointer to a new duration struct that contains the difference between the two. It may be useful to reduce the durations to a single unit (example: minutes), find the difference,...

  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • i need #6 but i believe #6 function needs to call #5 function. I would like...

    i need #6 but i believe #6 function needs to call #5 function. I would like this in C language, and have no pointers, arrays or strings (on function calling and parameters). Thanks! I have attached the other functions that you might need to call for function 6 1. Write and test a function called is_multiple_of that takes a integer n1, integer n2 and determines whether the second argument (n2) is a multiple of the first argument (n1). The function...

  • MUST USE C++ PLEASE READ THE QUESTION CAREFULLY!! ADD COMMENTS/EXPLAIN Question 1: Template Function with Pointer...

    MUST USE C++ PLEASE READ THE QUESTION CAREFULLY!! ADD COMMENTS/EXPLAIN Question 1: Template Function with Pointer Arguments Design and implement a template function, called swapt(T *p1, T *p2), which takes two parameters with the same generic data type. The function swaps the values of these two parameters. Test this function in the following main( ) : int main( ) {             int x = 30,   y = 40;             swapt(&x, &y);             cout << “x = “ << x...

  • in c++ please explain with answer 6. Given the following template function definition, which of the...

    in c++ please explain with answer 6. Given the following template function definition, which of the following is not a valid invocation of the function? template <class T> a. swap(s1,s2); void swap(T& left, T& right) b. swap(int1, int2); { c. swap(ch1, ch2); //implementation d. swap(int1, ch2); } int int1, int2; float flt1, flt2; char ch1, ch2; string s1, s2; 7. Why can you not use the swap template function to swap two complete arrays? template <class T> void swap(T& left,...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • Write a program (C++) that requests the current time and a waiting time as two integers...

    Write a program (C++) that requests the current time and a waiting time as two integers for the number of hours and the number of minutes to wait. The program then outputs what the time will be after the waiting period. Use 24-hour notation for the times. Include a loop that lets the user repeat this calculation for additional input values until the user says she or he wants to end the program.You can assume the wait time will always...

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT