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 36 37 38 39
|
#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 ;
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:\n" ;
std::cin >> hh >> sep >> mm >> sep >> ss ;
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 At The Location" ) ;
const unsigned int ending_time = get_secs_from_hh_mm_ss( "Give Me An End Time At The Location" ) ;
const unsigned int incr_secs = get_secs_from_hh_mm_ss( "Give Me An Increment Of Events At The Location" ) ;
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 << "The End Time Is:\n" << hh << ':' << mm << ':' << ss << '\n' ;
do {std::cout << hh << ":" << mm << ":" << ss << "\n"; start_secs += incr_secs;}
//these variables are simple containers - how do I increment by the variable - as += will not work with compiler!?
while (start_secs <= ending_time);
return 0;
}
//Output Is Formatted Correctly - However - The += not working//
|