Hi, I am trying to write a very simple bond calculation and I dont seem to get it right. I include what I have so far, also I know I didnt add the principal payment payoff but I will do it later on once I am done with coupon cashflow. Basically, I want a programm to calculate yearly cashflow (coupon / (1+ytm)^time) and add them in the end to get the value of the bond. I would appreciate any help pls. Thanks
#include <iostream>
#include <cmath>
using namespace std;
int main () {
int timetm,facevalue,coupon;
float yildtm;
double sum =0;
cout << "Enter time to maturity"<< endl;
cin >> timetm;
cout << "Enter facevalue of the bond" << endl;
cin >> facevalue;
cout << "Enter coupon rate (no decimals): " << endl;
cin >> coupon;
coupon = coupon /100;
cout << "Enter the yiled to maturity" << endl;
cin >> yildtm;
yildtm = yildtm / 100;
float cashflow = coupon / (pow (1+yildtm,timetm));
for (int i=0; i <timetm; i++){
sum = cashflow+cashflow;}
cout << "Your bond is equal to " << sum << endl;
my problem is when I run this, it gives me the value of the bond equal to 0, all the time. But I just want it to calculate cash flow each year and add them up to get the present value of the bond. the only thing that increments in the calculation is the timetm, so coupon / (pow (1+yildtm,timetm), will always be the same for each year and the only thing that would increment is timetm each year.thank you guys again.