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.
#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;
}
Comments
Leave a comment