CTIME and how to use it properly

Hello ya'll. Can someone show me the best way to implement ctime here? Super lost!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
    int a;
    int b;
    int c;
	cout << "Give Me A Start Time:\n";
	//Input would be HH:MM:SS
	cin   >> a;
	cout << "Give Me An End Time:\n";
	//input would be HH:MM:SS
	cin   >> b;
	cout << "Give Me An Increment Of Time, We Will Add It To The Start Time Until  We Reach The End Time:\n";
	cin  >> c;
	cout  << a << "\n" << b << "\n" << c << "\n";
	return 0;
}
use the chrono header file rather than the c-inherited <ctime>
take a look at this post - it should give you some ideas how to get data from keyboard and convert it into time structs: http://www.cplusplus.com/forum/beginner/208986/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>

unsigned int to_secs_since_midnight( unsigned int hh, unsigned int mm, unsigned int ss )
{ return hh*3600 + mm*60 + ss ; }

void from_secs_since_midnight( unsigned int total_secs, unsigned int& hh, unsigned int& mm, unsigned int& ss )
{
    hh = ( total_secs / 3600 ) % 24 ; // %24 to handle roll over to the next day
    mm = ( total_secs / 60 ) % 60 ;
    ss = total_secs % 60 ;
}

unsigned int get_secs_from_hh_mm_ss( const char* prompt )
{
    unsigned int hh, mm, ss ;
    char sep ;
    std::cout << prompt << " as hh:mm:ss " ;
    std::cin >> hh >> sep >> mm >> sep >> ss ; // input error handling elided for brevity
    
    std::cout << hh << ':' << mm << ':' << ss << '\n' ; // for testing; may be commented out
    
    return to_secs_since_midnight( hh, mm, ss ) ;
}

int main()
{
    const unsigned int start_secs = get_secs_from_hh_mm_ss( "give me a start time " ) ;
    const unsigned int incr_secs = get_secs_from_hh_mm_ss(  "give me the increment" ) ;

    const unsigned int end_secs = start_secs + incr_secs ;
    
    unsigned int hh, mm, ss ;
    from_secs_since_midnight( end_secs, hh, mm, ss ) ;
    std::cout << "\nend time is: " << hh << ':' << mm << ':' << ss << '\n' ;
}

http://coliru.stacked-crooked.com/a/12e78f54e70025f8
Gunner, JL;

This is exactly what I was looking for - thank you so very much. I will post my completed code on here when I have finished it. Thank you for the distinction; IE not using CTIME.
Topic archived. No new replies allowed.