Checkpoint 9.4.1.
- x.dollar += 2;
- x.dollar = x.dollar + 2;
- x.dollar -= 2;
- x.dollar = x.dollar - 2;
- x.cents -= 2;
- x.cents = x.cents - 2;
- x.cents += 2;
- x.cents = x.cents + 2;
Match the statement to its equivalent.
Try again.
after
, which compares two Time
s and returns a bool
that indicates whether the first operand comes after the second. Take a look at this active code.addTime
, which calculates the sum of two times. For example, if it is 9:14:30
, and your breadmaker takes 3 hours and 35 minutes, you could use addTime
to figure out when the bread will be done.
Time addTime(Time& t1, Time& t2) {
Time sum;
sum.hour = t1.hour + t2.hour;
sum.minute = t1.minute + t2.minute;
sum.second = t1.second + t2.second;
return sum;
}
currentTime
contains the current time and breadTime
contains the amount of time it takes for your breadmaker to make bread, then you could use addTime
to figure out when the bread will be done.12:49:30
, which is correct. On the other hand, there are cases where the result is not correct. Can you think of one?
addTime
.+=
and -=
. These operators provide a concise way to increment and decrement variables. For example, the statement sum.second -= 60.0;
is equivalent to sum.second = sum.second - 60;