I need to write a C program that incorporates a function to

I need to write a C++ program that incorporates a function to convert time in hours, minutes, and seconds to seconds and a main program that calls for that function.
I need to write a C++ program that incorporates a function to convert time in hours, minutes, and seconds to seconds and a main program that calls for that function.

Solution

// C++ code convert time in hours, minutes, and seconds to seconds

#include <iostream>
#include <string.h>
#include <fstream>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <iomanip>

using namespace std;

int totaltime(int hour, int minute, int second)
{
/* calculate total seconds */
int timeInseconds = second + (minute * 60) + (hour * 60 * 60);
return timeInseconds;
}

int main()
{
int hour, minute, second, timeInseconds;

cout << \"Enter hour: \";
cin >> hour;

cout << \"Enter minute: \";
cin >> minute;

cout << \"Enter seconds: \";
cin >> second;

timeInseconds =totaltime(hour,minute,second);

cout << \"Total seconds in \" << hour << \":\" << minute << \":\" << second << \" is \" << timeInseconds << endl;
return 0;
}

/*
output:

Enter hour: 12
Enter minute: 21
Enter seconds: 33
Total seconds in 12:21:33 is 44493


*/

I need to write a C++ program that incorporates a function to convert time in hours, minutes, and seconds to seconds and a main program that calls for that func

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site