Hi, I have been trying to calculate the bond price given a certain YTM using class method. Since the YTM and bond price are linked with each other(there is another question asking us to calculate the YTM with a given price),we put price and YTM in "private" and others variables in"public". Actually, this is the format given in my assignment.
I used "getvalue" to get the value of YTM, and used YTM in the formula of bond price calclation. However, the output of the price is infinite, while the output of price is right if I used a specific value of YTM(such as 0.05) in the formula. It means that I didn't successfully get right value of YTM. Can anyone tell me what's wrong with my program? Thanks a lot!!
#include <iostream>
#include <cmath>
using namespace std;