I've completed some homework for my intro to C++ class. The assignment was to create a C++ program that prompts the user for hours, minutes, and seconds and converts the timed event to seconds. I know it works, but I would like your opinion on the format and the use of variables, and to see if you would have done anything differently (i.e to make it look more professional).
#include <iostream>
using namespace std;
int main() {
int hours, minutes, seconds;
int hours_to_sec;
int mins_to_sec;
int total_sec;
cout << "Enter the amount of hours, minutes, and seconds in which the event happened.\n" << endl;
cout << "Hours: ";
cin >> hours;
cout << "Minutes: ";
cin >> minutes;
cout << "Seconds: ";
cin >> seconds;
hours_to_sec = hours * 3600;
mins_to_sec = minutes * 60;
total_sec = hours_to_sec + mins_to_sec + seconds;
cout << "The total number of seconds for the event: " << total_sec << endl;
return 0;
}


Sign In
Create Account


Back to top









