Converting Time To Decimal using C++
Posted by Samath
Last Updated: January 04, 2017

This program will accept a time from the user and convert it to decimal form. 

Code:

#include <iostream>
using namespace std;

int main()
{
    int hours = 0;
    int minutes = 0;
    int seconds = 0;

    cout << "Enter number of hours and minutes and seconds (H M S):  ";
    cin >> hours >> minutes >> seconds;

    cout << "The number of hours is: " << hours << endl;
    cout << "The number of minutes is: " << minutes << endl;
    cout << "And the number of seconds is: " << seconds << endl;


    float decTime = (float)hours + ((float)minutes / 60.0) + ((float)seconds / 3600);
    cout << decTime;
    return 0;
}