+= Fails in Compiler, Questions on Endless Run With Just a +;

Team,

Loving the support here; I am trying to compile the below - When it hits the
do { .. start_secs += incr_secs ..} --> It tells me it's a read-only variable - I'm rubbing my brain here - I'm like can I replace void here? I'm looking towards the Master JL - I've almost finished the program (evil laugh) - it will put the times in rows with other information!


I'm looking to put This Together.

Rules
1. Input Start Time
2. Input End Time
3. Input Increment Value
4. Add The Increment To Start Time, Show Each Time It Happens, Loop Until End Time Is Reached.

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//
Last edited on
well, it is
const unsigned int start_secs

const means constant. That means read only.
if you want to modify it, lose the const keyword off the definition.

Last edited on
It WORKED !!!
The output is just start + interval - but DOES the calculations to reach the end time.
Gonna Work on the output here to make sure it's correct - It needs to display start time as it changes.

Thanks !!!
It needs to display start time as it changes.
It doesn't. It will show the end time only. You need to call from_secs_since_midnight(...) within the loop for start_secs.

Note that it will not show a real time change.
Thanks All,

Have enough to be moving forward with.

Will post back soon ...
Topic archived. No new replies allowed.