[Solved] Using struct to display military time and add one second to user input (C++)


Here are some issues I found.
1. Don’t use struct when referring to variable types.
Incorrect: void getTime(struct Time *time)
Correct: void getTime(Time * time)

  1. Pass by reference, not pointer:
    void getTime(Time& time)

  2. You need to use either . syntax to refer to members or ->:
    cin >> time->hours; // if passed by pointer.
    cin >> time.hours; // if passed by reference.

  3. Don’t use type names when referring to variables.
    Incorrect: if ((int time.hours >= 0)
    Corrected: if ((time->hours >= 0)

  4. Remember “.” access when passed by reference, “->” when using pointers.

You should invest in a better text book or at least review the section on structures, classes, and pointers.

8

solved Using struct to display military time and add one second to user input (C++)