[spoiler title=”Lesson Video”]

Direct Download of Video (For mobile / offline viewing)(right click > save target as)

[/spoiler]

[spoiler title=”Lesson Source Code”]

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 |
#include <iostream> #include <cmath> using namespace std; int main(){ // 1 + 3 // i + j // +, -, *, /, % -- % is remainder 10%3 10/3 then give me the remainder, 1 //a, b ,c. total = a+b+c; total = 10; total = total+a+b+c; total += a+b+c; // +=, -=, *=, /= //Homework: Creating a simple interest calculator -- futureMoney = principle*(rate*time); //Creating a compound interest calculator int years = 0; double APR = 0.0, principal = 0.0, total = 0.0; cout < < "Enter your starting capital: "; cin >> principal; cout < < "\nEnter your APR (ex: 8.0% = 8): "; cin >> APR; cout < < "\nHow many years will your invest this money for: "; cin >> years; APR /= 100; total = principal * ( pow((1+APR),years) ); cout < < "\nThe amount in your account after: " << years << " years will be: " << total << endl; system("PAUSE"); return 0; } |

[/spoiler]

Homework is described and should be submitted here: http://beginnerscpp.com/forums/index.php/topic,55.0.html

**Cmath**

Cmath is a library that is used to perform mathematical functions in C++ programs. You could always create functions of your own to perform the tasks in this library (when you learn functions down the line). For a more complete listing of functions available inside the cmath library click here

**Raising a number to a power**

Raising a number to a power is very easy in C++ using the Cmath library. The reference linked above should show you examples. For powers you would use *pow(number, powerRaisedTo);* as your command.