Answer to Question #186031 in C++ for python

Question #186031

Create a structure called time. Its three members, all type int, should be called

hours, minutes, and seconds. Write a program that prompts the user to enter a

time value in hours, minutes, and seconds. The program should then store the time

in a variable of type struct time, and finally print out the total number of seconds.


1
Expert's answer
2021-04-27T02:10:53-0400
#include <iostream>
struct timer
{
    int hours;
    int minutes;
    int seconds;
};


int main()
{
    timer test;
    int time_in;
    std::cout << "Enter the number of hours : ";
    std::cin >>time_in;
    test.hours = time_in;
    std::cout << "Enter the number of minutes : ";
    std::cin >> time_in;
    test.minutes = time_in;
    std::cout << "Enter the number of seconds: ";
    std::cin >> time_in;
    test.seconds = time_in;
    std::cout << "Total seconds: " << 3600 * test.hours + 60 * test.minutes + test.seconds << std::endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS