... Performing the Interest Calculations with Standard Library Function pow
The for
statement (lines 22–28) executes its body 10 times, varying the unsigned int
control variable year
from 1 to 10 in increments of 1. This loop terminates when year
becomes 11. Variable year
represents n in the problem statement.
C++ does not include an exponentiation operator, so we use the standard library function pow
(line 24) from the header <cmath>
. The call pow(x, y)
calculates the value of x raised to the yth power. The function receives two double
arguments and returns a double
value. Line 24 performs the calculation , where a is amount
, p is principal
, r is rate
and n is year
.
The body of the for
statement contains the calculation 1.0 + rate
as pow
’s first ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.