In the while loop at the bottom I want to get the date to increase. The month is the only part that changes but I need for it to start over at 1 once it gets to 12 without resetting the other variable values. Any help is appreciated.
#include <iostream>
#include <math.h>
#include <iomanip>
usingnamespace std;
int main()
{
float prin, air = .1, np = 36, date, pay, mpr, mi, bal;
int n = 0;
cout<<"Enter principal amount: \n";
cout<<"$";
cin>>bal;
cout<<"Enter annual interest rate in decimal form: "<<endl;
cin>>air;
cout<<"Enter number of payments in months: \n";
cin>>np;
mpr = air / np;
pay = mpr * (bal / (1 - (1 / pow((1 + mpr), np))));
cout<<"Payment is: "<<pay<<endl;
cout<<"Payment: Due Date Number Payment Principal Interest Balance "<<endl;
while (n < np)
{
n++;
mi = bal * mpr;
prin = pay - mi;
bal = bal - prin;
cout.setf(ios::fixed);
cout<<setw(10)<<setprecision(2)<<n<<"/5/13"<<setw(7)<<n<<setw(11)<<pay<<" "<<prin<<" "<<mi<<" "<<bal<<endl;//in this line
}
return 0;
}
Now I have this but it is an infinite loop since the conditions are never met if np is over twelve.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
while (n < np)
{
n++;
if (n>12)
{
n = 1;
year++;
}
mi = bal * mpr;
prin = pay - mi;
bal = bal - prin;
cout.setf(ios::fixed);
cout<<setw(10)<<setprecision(2)<<n<<"/5/"<<year<<setw(7)<<n<<setw(11)<<pay<<" "<<prin<<" "<<mi<<" "<<bal<<endl;
}
return 0;
}