Skip to main content

Posts

Showing posts with the label and returns the equivalent time in seconds (type long).

Write a function called totalSeconds() that takes three int values - for hours, minutes and seconds - as arguments, and returns the equivalent time in seconds (type long). Create a program that does above task repeatedly until user hits 'N' or 'n' from keyboard.

 Here's a C++ program that includes the totalSeconds() function and a loop to repeatedly ask the user for input until they enter 'N' or 'n': #include <iostream> using namespace std; long totalSeconds(int hours, int minutes, int seconds) {     return hours * 3600 + minutes * 60 + seconds; } int main() {     char repeat = 'Y';     while (repeat == 'Y' || repeat == 'y') {         int hours, minutes, seconds;         cout << "Enter time in hours, minutes, and seconds: ";         cin >> hours >> minutes >> seconds;         long totalSecs = totalSeconds(hours, minutes, seconds);         cout << "Total seconds: " << totalSecs << endl;         cout << "Do you want to calculate again? (Y/N): ";         cin >> repeat;     }     return 0; } Output...